/** * The Average class implements an application that * calculates the average of a collection of integers * typed in at the keyboard. */ class Average { // -------------- the MAIN method -------------------------- public static void main(String [] args) throws Exception { double avg = 0.0; System.out.println("The args array contains the following numbers"); for(int i=0; i<args.length; i++) System.out.print(args[i] + " "); System.out.println(); if (args.length != 0) { for (int i=0; i<args.length; i++) avg += Integer.parseInt(args[i]); avg /= args.length; System.out.println("The average is " + avg); } else System.out.println("You didn't give me any numbers!"); } } // end of class Average