Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number. Here is a sample run:
Breaking it down
Reading input from the user and splitting it on a space will give us a String array. To count negative and positive numbers we will create a stream from the array and then use a lambda expression to filter values greater than zero and less than zero. Java 8 has a special object for collecting statistics such as count, min, max, sum, and average named SummaryStatistics. So for total and average, mapToDouble to DoubleSummaryStatistics.summaryStatistics() will give us those values for the user's input. Finally we will output the values to the console.