#How is this code producing an ArrayIndexOutOfBoundsException?

6 messages · Page 1 of 1 (latest)

grand lichen
#
int[][] prod = new int[a.length][a[0].length];

         for(int x=0; x<prod.length; x++)
             for(int y=0; y<prod[0].length; x++)
                 prod[x][y] = 0;```

```Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3```
dreamy stagBOT
#

This post has been reserved for your question.

Hey @grand lichen! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

coral karma
#

you;re doing x++ in the inner loop instead of y++

grand lichen
#

oh

#

silly me