// CSE 142 Lecture 9 // Advanced if/else, Cumulative algorithms import java.util.*; // For Scanner // Demonstrates cumulative algorithms other than sum. public class CumulativeAlgorithms { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("How many numbers will you type? "); int count = console.nextInt(); // Start the counts/total at 0. int negative = 0; int positive = 0; int total = 0; // Start max and min with a value that will be replaced by the first // number the user enters. We'll see a better way to do this on Friday. int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; for (int i = 0; i < count; i++) { System.out.print("Type a number? "); int number = console.nextInt(); max = Math.max(number, max); min = Math.min(number, min); total += number; if (number < 0) { negative++; } else if (number > 0) { positive++; } } System.out.println("The average of the numbers you typed is: " + (double)total / count); System.out.println("The minimum of the numbers you typed is: " + min); System.out.println("The maximum of the numbers you typed is: " + max); System.out.println("You typed " + negative + " negative numbers"); System.out.println("You typed " + positive + " positive numbers"); } }