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,570
  • 1
  • 19
  • 50

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
  • 374,785
  • 51
  • 663
  • 734