I'm working on a question where I need to compare the values inside a 2D Array in java. For example:
int N = 2, c = 2;
int [][] arr = new int[N][c];
System.out.println("Enter the values to a 2D array: ");
for(int i=0; i<N;i++) {
for (int j=0;j<c;j++) {
arr[i][j]=in.nextInt();
}
}
So in the above code, the user enters the values inside a 2d array.
Now I want to compare if arr[i]>=0 and arr[j]>=0 separately and if yes, I need to perform some other operation on this.
But I'm not able to do it that way. Example:
for(int i=0; i<N;i++) {
for (int j=0;j<c;j++) {
if (arr[i]>=0 && arr[j]>=0) {
//Some operation//
}
}
}
Kindly suggest me a way to do this operation - comparing the values individually. Thank you.