1 /* 2 * File: Average.java 3 */ 4 5 import java.io.*; 6 7 public class Average 8 { 9 public static void main (String args[]) throws IOException 10 { 11 // declaring a constant variable 12 final int NUM = 5; 13 14 int number; 15 int total = 0; 16 int counter = 1; 17 double average; 18 19 // while loop and if tests 20 while (counter <= NUM) 21 { 22 /* uses method from Console class to read formatted input - 23 prints the argument as a prompt, then reads an int 24 terminated by a newline */ 25 number = Console.readInt("Type in an integer: "); 26 total += number; 27 counter ++; 28 } 29 30 // cast to get floating point arithmetic 31 average = (double)total / NUM; 32 System.out.println ("The average of these numbers is " + average ); 33 } 34 }