Using try/catch to alert user of negative number entered, nestled in loop
<p>I have created a program to find the average of positive numbers only. The program works fine, however, I am looking to improve it. At the moment when a user enters a negative number the loop ignores it. However I would like an error message to come up once the user enters a negative number. </p>

<p>I have done some research and I believe I need to add a try catch within my loop however, I'm not sure how I would implement it into my existing code.</p>

<p>Here is my code so far; </p>

<pre><code>System.out.println("program to find the arithmetic mean (average) of a list of positive numbers  ");
System.out.println("=======================");
System.out.println();
System.out.print("How many numbers do you want to enter ? ");
numbers = inputLine.nextInt();
System.out.println("Enter " +numbers+ " Numbers : "); 

for (start=0; start&lt;numbers; start++) {
   int number;
   do {
      number = inputLine.nextInt();
   } while (number &lt; 0);
   sum = sum + number;
}

if (numbers == 0) {
    System.out.print("program terminated......");
    System.exit(0);
}

armean = sum/numbers;
System.out.print("Average of all positive numbers entered is: " +armean);
</code></pre>