i have this code. i am trying to set a grid and start at c. it then moves to the next value - 1, so in this case, would move to a 4.
However, in my IF statement, i want to put if(position surrounding c == c-1){then change that position to c; then c-1;}
i dont know how to specify the position without hardcoding it i.e. [2][1]
is there a way to do so?
EDIT : another way of putting it is ... is there a way to search my array for the c-1 in my IF
public class Array{
public static void main(String[] args) {
int c = 5;
int[][] startPos =
{{3,4,c,6,7},
{2,3,4,6,7},
{1,2,3,6,7},
{0,1,2,6,7}};
for (int row = 0; row < startPos.length ; row++ ) {
for (int col = 0; col < startPos[row].length; col++ ) {
System.out.print(startPos[row][col]);
}
System.out.println();
}
if(startPos[0][1] == c-1){
startPos[0][1] = c;
}
for (int row = 0; row < startPos.length ; row++ ) {
for (int col = 0; col < startPos[row].length; col++ ) {
System.out.print(startPos[row][col]);
}
System.out.println();
}
}
}