3

I'm trying to type an Array but I get java.lang.ArrayIndexOutOfBoundsException: 3

I googled it and I know everything about this exception but I can't do anything to solve this stupid problem.

public static void main(String[] args) {
    int [][] matrix = new int[3][5];

    for (int i =0; i<matrix.length; i++) {
        for (int ii=0; ii<matrix[i].length; i++) {
            System.out.print(matrix[i][ii]);
        }
        System.out.println(" \n");      
    }       
}
Naman Gala
  • 4,670
  • 1
  • 21
  • 55

1 Answers1

8

You got a typo:

for (int ii=0; ii<matrix[i].length  ;i++)

should be

for (int ii=0; ii<matrix[i].length  ;ii++)
Eran
  • 387,369
  • 54
  • 702
  • 768