title: When populating a table using 2D array in Java, there's an error, what is wrong with this code?
body: <p>I'm starting my first steps with 2D arrays in Java. I require some help on a practical example. The below code should store students and their results for the 3 different courses in a table but the code throws an error. The error is caused by the line <code>int studentResults[x][y] = sc.nextInt();</code> Any ideas? Thanks.</p>
  
  <pre><code>import java.util.*;
  
  class CalcAverage 
  {
      public static void main(String[] args) 
      {
          Scanner sc = new Scanner(System.in);
  
          System.out.print("how many students?: ");
          int nbrOfStudents = sc.nextInt();
  
          int[][] studentResults ;
  
          studentResults = new int[nbrOfStudents][3] ;
  
          for (int x = 0 ; x &lt; nbrOfStudents  ; x++)
          {
              System.out.println("Student " + (x + 1) + " : ");
  
              for (int y =0 ; y &lt; 3 ; y++)
              {
                  System.out.println("enter result course " + (y + 1) + " : ");
                  int studentResults[x][y] = sc.nextInt();
              }
          }
  
      }// end main
  }//end class
  </code></pre>