what is he problem and is there any other way for sorted matrix???
import java.util.Scanner;
public class Main {
static Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
int testCases = scn.nextInt();
while (testCases > 0) {
int[][] array = takeInput();
//display(array);
//element to be searched
//int[][] array = { { 11, 12, 13, 14 }, { 21, 22, 23, 24 }, { 31, 32, 33, 34 }, { 41, 42, 43, 44 } };
//display(array);
int x = scn.nextInt();
int ans = linearSearch(array,x);
System.out.println(ans);
testCases--;
}
// int[][] array = { { 11, 12, 13, 14 }, { 21, 22, 23, 24 }, { 31, 32, 33, 34 }, { 41, 42, 43, 44 } };
// display(array);
}
public static int[][] takeInput() {
//System.out.println("Enter no of rows");
// here rows =n, columns = m
int n = scn.nextInt();
int m = scn.nextInt();
int[][] arr = new int[n][m];
for (int row = 0; row < n; row++) {
for (int col = 0; col < m; col++) {
arr[row][col] = scn.nextInt();
}
}
return arr;
}
public static void display(int[][] arr) {
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
public static int linearSearch(int[][] arr, int x) {
int ans = 0;//initially no element found
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if(arr[i][j] == x) {
ans = 1;
}
}
}
return ans;
}
}