/** * 在二维数组中查找数字 * 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排列。 * 请完成一个方法,输入这样的一个二维数组和一个整数,判断数组中是否存在改整数。 * @param ints 二维数组 * @param rows 二维数组的行数 * @param columns 二维数组的列数 * @param number 要查找的目标数字 * @return 目标数字是否存在于二维数组中 */ public static boolean findNumber(int[][] ints,int rows,int columns, int number){ boolean find = false; //判断二维数组中是否存在数字 if (rows > 0 || columns > 0){ int row = 0; int col = columns -1; while (row < rows && col > 0){ if(ints[row][col] == number){ find = true; break; }else if (ints[row][col] > number){ col --; }else { row ++; } } } return find; }