I know that I am making a mistake somewhere in this code, but I cannot figure it out. Player1.getId (); returns a value of 1 so you know. I am trying to print the index of an 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 are both equal 9. Any help would be great.
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);