/** * Compute the average of a list of numbers entered on the command * line. Non-numeric values entered on the command line will be * ignored. For example, to average 1, 2, and 3, you would write * % java Average 1 2 3 * * @author Carla Caffeinated * @author Carl Caffeinated * @author Samuel A. Rebelsky * @author YOUR NAME HERE * @version 1.1 of April 2004 */ public class Average { public static void main(String[] args) { float sum = 0; // The sum of all the values entered. int count = 0; // The number of values entered. SimpleOutput out = new SimpleOutput(); // Step through the values, adding each in turn. Skip those // that aren't valid. for (int i = 0; i < args.length; i = i+1) { try { sum = sum + Float.parseFloat(args[i]); count = count + 1; } catch (NumberFormatException nfe) { // Skip it. } } // for // Print the average. out.println("The average is: " + (sum/count)); } // main(String[]) } // class Average