/* Input numbers into an array and calculate their avarage. An example to illustrate the case where the size of the array is not declared in advance. */ import java.io.*; class ArrayEx2 { public static void main(String[] args) throws IOException { BufferedReader stdin; stdin = new BufferedReader (new InputStreamReader (System.in)); int sizeOfArray; int sum = 0; double avarage; System.out.print ("Enter the number of entrees? "); System.out.flush(); sizeOfArray = Integer.parseInt(stdin.readLine()); // declare the array int[] numbers = new int[sizeOfArray]; // input numbers into the array for (int index=0; index != sizeOfArray; index++) { System.out.print("Enter entry #" + index + ": "); System.out.flush(); numbers[index] = Integer.parseInt(stdin.readLine()); } // calculate the sum of the numbers in the array for (int index=0; index != sizeOfArray; index++) sum = sum + numbers[index]; // calculate the avarage of the numbers avarage = (double)sum/(double)sizeOfArray; System.out.println("The avarage of the numbers in the array is " + avarage); } }