Skip to content
Advertisement

Creating user input for randomized 2D java array issue – OutOfBoundsException

Trying to create a 2D array that takes the users input for rows and columns. The numbers inside the array are then randomized from 0 to 100. I am getting the following error:

Enter rows for the array: 3

Enter columns for the array: 2

Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3 at test2.main(test2.java:17)

Here is my code:

JavaScript

Advertisement

Answer

You should use separate variables to run the loops.

JavaScript

}

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement