I know I could use the contains()
method, but I can't figure out how to use it for a two dimensional array and how to return something.
Right now my code looks like this:
public class Array {
public static void main(String[] args) {
int z = 2;
int[][] data = new int[1][4];
data[0][0] = 0;
data[0][1] = 3;
data[0][2] = 2;
data[0][3] = 6;
for (int i = 0; i < data[0].length; i++) {
if (data[0][i] == z) {
System.out.println("Array data has z");
}
}
}
}
Checking with a loop works, but we were advised to use the contains
method.
But how can I use the contains method in my case?