I have 2D array but if I change x coordinate, everytime I get wrong result.
int[][] arr = {{0, 2, 0, 0, 1},{0, 2, 0, 0, 1},{0, 2, 0, 0, 1},{0, 2, 0, 0, 1},{0, 2, 0, 0, 1}};
int now, previous;
for (int i = 1; i < 5; i++) {
for (int j = 0; j < 5; j++) {
now = arr[i][j];
previous = arr[i-1][j];
}
}
The result of variable now is 0, 2, 0, 0, 1… Why I want to have only 2, 0, 0, 1
If I change i coordinate of variable for Example i = 1 the output is still 0, 2, 0, 0, 1…
Do you know where is problem?
Thanks
because i corresponds to the outer array in your example. what you have will print
0, 2, 0, 0, 1four times. I gather what you want is to show2, 0, 0, 1five times… for that you should be doing