Hi all,
I have created a java program that reads in the number of rows and columns entered by the user, and creates a board of that size. Then, it takes in the position of cells (x, y) that the user wants to make live on that board. -1 will exit the program.
The program runs great, however I am running into one issue.
Say the user specifies a grid of 25 rows by 25 columns.
If the user then chooses a cell, 2 25, to make live... the following exception occurs (on the console, there are no compilation errors):
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 25
at LifeGame.setPos
at LifeGame.main
setPos looks like this:
public void setPos(int x, int y)
grid[x][y] = true
That's pretty straightforward, and I don't think it's the issue. The only thing I can think of is that it's taking in 0-24 rather than 1-25.
A simple workaround could be, after taking in x and y from the user, simply add 1 to each:
y = y + 1
x = x + 1
Edit: On second thought, this will simply change the the grid to 26 x 26. Not what I want. Is there a way to allow the user to input 1-25, rather than 0-24, for the cell positions?