title: Java input mismatch error using scanner
body: <p>I am a novice Java student and am trying to complete a program that uses the scanner to input 5 students' names, and then a loop within to get 3 grades for each student.  I am stuck as I keep getting an Input Mismatch error and I don't know why.  I have tried to correctly match what kinds of input are coming in to the variables.  Any help would be greatly appreciated!</p>
  
  <p>This is what I have:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class StudentGrades {
    public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      // Declare arrays, grades to hold [student #][course] and correspond to the grade. studentNames to be paralell and hold the names.
      int [][] grades;
      grades = new int[5][3];
      String[] studentNames = new String[5];
      int studentNumber = 0;
      int courseNumber = 0;
  
    // Create loops to put values in both arrays, using student# as a counter
    if (studentNumber &lt; 5) {
      System.out.println("Enter the student name");
      studentNames[studentNumber] = input.next();
      // Nested loop to enter the grades
      if (courseNumber &lt; 5) {
        System.out.println(" Enter a grade for " + studentNames[studentNumber]+" for course #" + courseNumber);
        grades[studentNumber][courseNumber] = input.nextInt();
        courseNumber = courseNumber + 1;
      }
    studentNumber = studentNumber + 1;
      }
  
    }
  
  }
  </code></pre>
  
  <p>And this is what I get:</p>
  
  <pre><code>Exception at thread "main" java.util.InputMismatchException
  at java.util.Scanner.throwfor{Scanner.java:909}
  at java.util.Scanner.next{Scanner.java:1530}
  at java.util.Scanner.nextInt{Scanner.java:2160}
  at java.util.Scanner.nextInt{Scanner.java:2119}
  at StudentGrades.main{StudentGrades.java:20}
  </code></pre>