The
has a two-dimensional array, each row, each column is incremented, finds a target value, and returns true if it exists otherwise false. The
starts at the lower-right corner, or to the left if it is greater than the target value, or downward if it is less than the target.
package searchtest;
public class Erweiarray {private static Boolean find (int[][] A, int val) {Boolean find = false;
int rows = A.length;
int columns = A[0].length;
if (A! = null && rows > 0 && columns > 0) {int row = 0; int column = Columns-1;
The subscript for the row and column is 0 while (Row < rows && column >= 0) {if (a[row][column] = = val) {
find = true;
Break
} else if (A[row][column] > val) {column--;
} else {row++;
}}} return to find;
public static void Main (string[] args) {int[][] tes = {{1, 2, 8, 9}, {2, 4, 9, 12}, {4, 7, 10, 13},
{6, 8, 11, 15}};
System.out.print (Find (TES, 18));
System.out.print (Find (TES, 7)); }
}