标签:元素 结果 row inf [] 停止 for循环 targe class
for(row = 0,column = column_len-1;column >= 0&&row <row_len;)
当循环的条件不满足column >= 0 && row <row_len时,跳出for循环,执行for循环以下的代码。
public class FindArray { public static void main(String[] args) { int[][] arr = { {1,2,8,9},{2,4,9,12},{4,7,10,13},{6,8,11,15}}; System.out.println(Find(7,arr)); } public static boolean Find(int target,int[][] array) { int row_len = array.length; int column_len = array[0].length; int row = 0; int column = column_len-1; for(row = 0,column = column_len-1;column >= 0&&row <row_len;) { if(target == array[row][column]) { return true; } if(array[row][column] > target) { column--; continue; } if(array[row][column]<target) { row++; continue; } } return false; } }
二维数组中的查找的运行结果如下:
标签:元素 结果 row inf [] 停止 for循环 targe class
原文地址:https://www.cnblogs.com/Qinstudy/p/10053597.html