title: Java program calculating mean with exceptions
body: <p>Write a program that calculates the average of N integers. The program should prompt the user to enter the value for N and then afterward must enter all Nnumbers. If the user enters a non-positive value for N then an exception should be thrown (and caught) with the message "N must be positive." If there is any exception as the user is entering the N numbers then an error message should be displayed and the user prompted to enter the number again. If the user does not enter an integer, the program must request the use to re-enter the value.</p>
  
  <p>Am i throwing the exception correctly??</p>
  
  <pre><code>import java.util.Scanner;
  import java.util.InputMismatchException;
  
  class Playground {
      public static void main(String[ ] args) {
          int sum = 0, mean;
          System.out.println("Please enter number of integers");
          Scanner sc1 = new Scanner(System.in);
          int counter = sc1.nextInt();
  
          if ( counter &lt;= 0 ) {
              throw new InputMismatchException("N must be positive");
          }
          else {
              System.out.println("Please enter "+counter+" numbers");
          }
  
          for (int i =0; i&lt; counter; i++) {
              int inputnum = sc1.nextInt();
              if ( inputsum &lt;= 0){
                  throw new InputMismatchException("Please enter again");
                  continue;
              }
              sum = sum+inputnum;
              System.out.println();
          }
  
  
          mean = sum/counter;
  
          System.out.println(mean);
  
      }
  }
  </code></pre>