Note: Java can be used to solve this problem by using the length method of the string.
1 Public classFindNum {2 Public Static voidMain (string[] args) {3 intArry[][] = {{1, 2, 8, 9}, {2, 4, 9, 12}, {4, 7, 10, 13}, {6, 8, 11, 15}};4 intFindNum = 12;5 if(Find (Arry,findnum)) {6System.out.println ("Find");7 }8 Else9System.out.println ("Not find");Ten One } A - Private Static BooleanFindint[] Arry,intfindnum) { - if(arry==NULL){ theSystem.out.println ("Arry is null!"); - return false; - } - BooleanFindflag =false;//Set Search Flags + introws = arry.length;//get the total number of rows in a two-dimensional array - intRow = 0; + intColum = arry[0].length-1;//number of columns in an array A while(row<rows&&colum>=0){ at if(arry[row][colum]==findnum) { -Findflag =true; - Break; - } - Else if(arry[row][colum]>findnum) -colum--; in Else -row++; to + } - returnFindflag; the * } $ Panax Notoginseng -}
Pro3 Lookup in a two-dimensional array (Java)