I have a 2D int[][] and am trying to write a function that locates a 0 in that array and returns an array with its coordinates.
I came up with this:
public int[] locateZero(int[][] array) {
int[] coordinates = new int[2];
for (int i=0; i < array.length; i++) {
for (int j=0; j < array[0].length; j++) {
if (array[i][j] == 0) {
//The following line doesn't work!
coordinates.add(i, j);
}
}
}
return coordinates;
}
NetBeans keeps underlying the add method, stating that it cannot find it.
Could someone help me, please?
It's a stupid problem, I know. I'm a Java noob.
coordinatesis not a list there are no way to usecoordinates.add(i, j);with arraycoordtinates[0] = i;andcoordtinates[1] = j;