Iam trying to create a java program in which, i will be able to change the position of value 1 to specific positions into an array.For example i have the value 1 in the position [5][4] and i want to move it to the next (or the previews position) and delete the value 1 and store the value 0 into the previous position. My problem is that i can move the value 1 but i can't delete it from the previous position(store to the previous position the value 0).My code is the following:
for (int row = 0; row < 6; row++) {
for (int col = 0; col < 6; col++) {
int randomPosition = r.nextInt(2);
array[row][col] = 0;
array[2][3] = 1;
array[4][4] = 1;
if (array[row][col] == 1) {
array[row][col] = 0;
if (randomPos == 0) {
array[row - 1][col] = 1;
} else if (randomPos == 1) {
array[row][col - 1] = 1;
} else if (randomPos == 2) {
array[row + 1][col + 1] = 1;
}
}
}
}
for (int row = 0; row < cells.length; row++) {
for (int col = 0; col < cells[row].length; col++) {
System.out.print(" " + cells[row][col]);
}
}