// The for loop example: find the avarage and the highest // grades given a series of scores import java.util.Scanner; class LoopExample3B { public static void main (String[] args) { Scanner scan = new Scanner(System.in); int grade, sum = 0; int number; // needs not be initialized, because it is an input int max = -1; System.out.print ("Enter number of grades: "); System.out.flush (); number = scan.nextInt(); for (int i = 1; i <= number; i++) { System.out.print ("Enter grade " + i + ": "); System.out.flush (); grade = scan.nextInt(); if (max < grade) max = grade; sum = sum + grade; } if (number == 0) System.out.println ("No grades enterred."); else { System.out.println ("The avarage grade is " + (sum / number)); System.out.println ("The highest grade is " + max); } } }