what is causing Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
<pre><code>public static void sumrowsandcols(int[][] a) {

    int[] sum = new int[5];
    int i, j, x;
    // Sum of rows
    for (i = 0; i &lt; 5; i++) {
       for (j = 0; j &lt; 5; j++) {
           sum[i] += a[i][j];
       }
    }
    for (x = 0; x &lt; 5; x++) { 
        System.out.println(sum[x]);
    }

    // Sum of columns
    for (i = 0; i &lt; 5; i++) {
       for (j = 0; j &lt; 5; j++) {
           sum[i] += a[j][i];
       }
    }

    for (x = 0; x &lt; 5; x++) { 
        System.out.println(sum[x]);
    }
  }


  public static int[][] generateArray(Scanner myScanner) {

    int numbers[][] = new int[5][5];
    int i, j, x;
    for (i = 0; i &lt; 5; i++)
      System.out.println("Please enter 5 integers for row " + (i+1));     
      for (x = 0; x &lt; 5; x++) {
        j = myScanner.nextInt();
        numbers[i][x] = j;
      } 
      return numbers;
  }

  // Main method. Collection happens, then calls sumrowsandcols. 

  public static void main(String[] args) {   

    int i, j, x;
    Scanner myScanner = new Scanner(System.in);    
    int[][] numbers = generateArray(myScanner);

    // Collect information by row        


    // Print sum of rows and columns
    sumrowsandcols(numbers);    
   }
</code></pre>
