'Why cant you subract a value from a for loop within an 2DArray but works vice versa(Adding a value to the 2DArray)?
Just like the game minesweeper I want the "O"s to change to "1"s if the borders are next to the "X"s, the board[i][j] will only change to "1"s if and only you add 1, e.g.. board[i][j+1] or board[i+1][j+1] will change the nearby "O"s to "1"s, but when subtracting, the values remain the same e.g. board[i-1][j] = "O".
Why cant you subtract?
String board[][] = {{"O", "O", "O", "O", "O", "O"},
{"O", "O", "O", "X", "O", "O"},
{"O", "O", "O", "O", "O", "O"},
{"O", "O", "X", "O", "O", "O"},
{"O", "O", "O", "O", "X", "O"},
{"O", "O", "O", "O", "O", "O"},
};
for(int i = 0; i < 6; i++) {
for(int j = 0; j < 6; j++) {
if(board[i][j] == "X") {
board[i-1][j] = "1";
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|