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");      
    }       
}
0

1 Answer 1

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++)
Sign up to request clarification or add additional context in comments.

3 Comments

I feel so stupid , thank u very much for answering . I won't use similar letters again.. I spent two hours just looking for an answer . Thank you
@AhmadMorad You're welcome.
@AhmadMorad, you can use i, j, k as variable names, so that you can differentiate among them.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.