import java.util.Scanner;
/** 
 * A program to illustrate exception handling.
 *
 * @author Nancy Harris
 * @version V1 - with potential exceptions in place
 */
public class ExceptV1
{
   /**
    * 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
      int [] numbers;   // array to use to process mean
      int total, avg;   // the sum and final average
      int count;           // count

      keyboard = new Scanner(System.in);
      
      // pull in argument from command line to build array.
		// causes error if none there
      count = Integer.parseInt(args[0]);        
     
	   System.out.println (" count is " + count);
      
		numbers = new int [count];
   
      for (int ii = 0; ii < numbers.length; ii++)
      {
         System.out.print("Enter a number: ");
         numbers[ii] = keyboard.nextInt();
         System.out.println();
      }
    
	   total = 0;    // initialization for computing sum of array elements
     
	    
      System.out.println (" Here is the contents of the array ");   
	   for (int ii = 0; ii < numbers.length; ii++)
      {  
	             total += numbers[ii];
                System.out.print (" " + numbers[ii] + "  ");
	   }
	   	     
		System.out.println ();
		System.out.println (" The sum of the array elements is " + total);
      
		System.out.println (" numbers.length is " + numbers.length);
	
		avg = total / numbers.length;
      System.out.println (" The average of the numbers in the array is " + avg);
    
	   // The printf statement causes a
		// java.util.IllegalFormatConversionException: f!= java.lang.Integer 
		// error
		// System.out.printf("\nTotal: %f\tAverage: %f", total, avg);
   }
}
      