import java.util.Scanner;
/** 
 * A program to illustrate exception handling.
 *
 * @author Nancy Harris
 * @version V2 - with correction of printf error and change to double
 */
public class ExceptV2
{
   /**
    * A program to read in a series of 
    * double values and compute their mean
    * 
    * @param args Command line arguments
    */
   public static void main(String [] args)
   {
      Scanner keyboard;    // input
      double [] numbers;   // array to use to process mean
      double total, avg;   // the sum and final average
      int count;           // count

      keyboard = new Scanner(System.in);
      
      // pull in argument to build array.
      count = Integer.parseInt(args[0]);        
      
      numbers = new double [count];
      
      for (int ii = 0; ii < numbers.length; ii++)
      {
         System.out.print("Enter a number: ");
         numbers[ii] = keyboard.nextDouble();
         System.out.println();
      }
      
      total = 0;
      for (int ii = 0; ii < numbers.length; ii++)
      {
         total += numbers[ii];
      }
      
      avg = total / numbers.length;
      
      System.out.println("List of numbers");
      for (int ii = 0; ii < numbers.length; ii++)
      {
         System.out.printf("%f \t", numbers[ii]);
         
         if ((ii + 1) % 5 == 0)
            System.out.printf("\n");
      }
      System.out.printf("\nTotal: %f\tAverage: %f", total, avg);
   }
}
      