import java.io.*; class Numbers3 { // Read a number of integers and store them in an array. // Find and print the biggest and smallest number and the average. // Prints an error message if the maximum number of numbers is exceeded static final int SENTINEL = -999; static final int MAXNUMS = 10; public static void main (String[] args) throws IOException { int [] data; int count=0,n; double average; BufferedReader in = Text.open(System.in); data = new int[MAXNUMS]; try { for(count=0; ;count++) { System.out.print("Enter number "+(count+1)+" (or "); System.out.print(SENTINEL+" to finish): "); n=Text.readInt(in); if(n==SENTINEL) break; data[count]=n; } } catch(ArrayIndexOutOfBoundsException e) { System.out.println("Cannot take more than "+MAXNUMS+" numbers"); } System.out.println("The numbers entered were:"); NumberOps.printall(data,count); System.out.println("The biggest is: "+NumberOps.biggest(data,count)); System.out.println("The smallest is: "+NumberOps.smallest(data,count)); System.out.print("The average is: "); average=NumberOps.average(data,count); System.out.println(Text.writeDouble(average,5,3)); } }