The problem
Write a program that asks the user to enter a series of single digit numbers with nothing separating them. The program should display the sum of all the single digit numbers in the string. For example, if the user enters 2514, the method should return 12, which is the sum of 2, 5, 1, 4. The program should also display the highest digit in a string and lowest digits in string.
Collecting user input from the keyboard we will separate the string on each digit using a regular expression then create a java 8 stream. At this point the stream contains elements of type string so we will need to convert to doubles by calling mapToDouble
function. Finally calling summaryStatistics
will create an object DoubleSummaryStatistics to allow calling multiple reduction operations on a stream such as max, min and sum. Attempting to create a stream and calling multiple operations will result in a stream closed exception.