import java.io.*; class Numbers2a { // Read a number of integers from a file named as a command line // argument and store them in an array. // Find and print the biggest and smallest number and the average. static final int MAXNUMS = 10; public static void main (String[] args) throws IOException { int [] data; int count=0; BufferedReader reader=null; double average; if(args.length!=1) { System.out.println("Must have exactly one file name as argument"); System.exit(1); } try { reader = new BufferedReader(new FileReader(args[0])); } catch(FileNotFoundException e) { System.out.println("No file '"+args[0]+"' found"); System.exit(2); } data = new int[MAXNUMS]; try { for(;;) data[count++]=Text.readInt(reader); } catch(EOFException e) {} catch(ArrayIndexOutOfBoundsException e) { System.out.println("Cannot take more than "+MAXNUMS+" numbers"); } count--; 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 position of the biggest is: "); System.out.println(NumberOps.posBiggest(data,count)+1); System.out.print("The position of the smallest is: "); System.out.println(NumberOps.posSmallest(data,count)+1); System.out.print("The average is: "); average=NumberOps.average(data,count); System.out.println(Text.writeDouble(average,5,3)); } }