title: How to display the "Invalid numbers with conditions" in Java?
body: <p>Here is the problem with my output:</p>
  <pre class="lang-none prettyprint-override"><code>Enter number of students: 3
  Enter the grade for student 1:
  -2
  Invalid grade, try again...
  Enter the grade for student 2:
  -3
  Invalid grade, try again...
  Enter the grade for student 3:
  110
  Invalid grade, try again...
  The average is 35.0
  </code></pre>
  <p>But in the sample output session as follow:</p>
  <pre class="lang-none prettyprint-override"><code>Enter number of students: 3
  Enter the grade for student 1:
  55
  Enter the grade for student 2:
  108
  Invalid grade, try again...
  Enter the grade for student 2:
  56
  Enter the grade for student 3:
  57
  The average is 56.0
  </code></pre>
  <p>Can you see the <code>-2</code>, the <code>-3</code> and <code>110</code> did not break the loop and it kept asking for new input? Instead of showing <code>108</code> on the sample and immediately break the loop and ask user to prompt the input of <code>student 2</code> again.</p>
  <p>Here is my code:</p>
  <pre class="lang-java prettyprint-override"><code>public static int theSumOfGrade(int[] newArray, int grade) {
      int sumGrade = 0;
      for(int i = 0; i &lt; newArray.length; i++) { // for i &lt; array length
          sumOfGrade += newArray[i];  // the sum will be added up with all the values inside the array
      }
      return sumOfGrade;
  }
  
  public static int[] getNumberOfStudentsArray(Scanner input) { // Number of students input method
      System.out.printf(&quot;Enter number of students: &quot;); // Prompt the number of students from the user
      int numberOfStudents= input.nextInt(); // Scanner Object in with numberOfStudents variable
  
      int studentGrades[] = new int[numberOfStudents]; // Assign to new Array
  
      for (int i = 0; i &lt; numberOfStudents; i++) {
          System.out.println(&quot;Enter the grade for student &quot; + (i+1) + &quot;:&quot;  );
          studentGrades[i] = input.nextInt();
  //        for (int j = 0; j &lt; studentGrades.length; j++) {
  //        }
          if (studentGrades[i] &lt; 0 || studentGrades[i] &gt; 100) {
              System.out.println(&quot;Invalid grade, try again&quot;);
              continue;
          }
      }
      return studentGrades;
  } // end of getNumberOfStudentsArray()
  </code></pre>