I know I'm making an error somewhere in this code, but I can't figure it out. The player1.getId(); returns a value of 1 just so you are aware. I'm trying to print the index of the array where the value is 1. At the end of the code, I expected currentX to be 0 and currentY to be 0, but they were both 9. Any help would be super.
int[][] grid = {
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3}
};
int currentX = 0;
int currentY = 0;
grid[0][0] = player1.getId();
grid[0][9] = 2;
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < grid[0].length; j++) {
if (grid[i][j] == player1.getId());
{
currentX = i;
currentY = j;
}
System.out.print(grid[i][j]);
}
}
System.out.println();
System.out.println("Player1 is currently in row " + currentX + " and column " + currentY);