/* * Average.java */ import java.io.*; public class Average { public static void main (String args[]) throws IOException { // declaring a constant variable final int NUM = 5; int number; int total = 0; int counter = 1; double average; // while loop and if tests while (counter <= NUM) { /* uses method from Console class to read formatted input - prints the argument as a prompt, then reads an int terminated by a newline */ number = Console.readInt("Type in an integer: "); total += number; counter ++; } // cast to get floating point arithmetic average = (double)total / NUM; System.out.println ("The average of these numbers is " + average ); } }