试题3:二维数组中的查找
来源:互联网 发布:linux查cpu核数 编辑:程序博客网 时间:2024/05/16 17:39
题目:在一个二维数组中,每一行按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请输入一个函数,输入这样一个二维数组和一个整数,判断数组中是否含有该整数.
public class Test03 {public static boolean findNum(int [][]a,int rows,int columns,int key){//rows 与columns表示矩阵的行数与列数if (a!=null&&rows>0&&columns>0) {int row=0;//第一行int colomn=columns-1;//最后一列while(row<rows&&colomn>=0){//查找比较有没有相同的数if (a[row][colomn]==key) {return true;}else if (a[row][colomn]<key) {row++;}else {colomn--;}}}return false;}public static void main(String[] args) { int[][] testarray=new int[4][4]; testarray[0][0]=1; testarray[0][1]=2; testarray[0][2]=8; testarray[0][3]=9; testarray[1][0]=2; testarray[1][1]=4; testarray[1][2]=9; testarray[1][3]=12; testarray[2][0]=4; testarray[2][1]=7; testarray[2][2]=10; testarray[2][3]=13; testarray[3][0]=6; testarray[3][1]=8; testarray[3][2]=11; testarray[3][3]=15; System.out.println(findNum(testarray,3,3,1)); }}
阅读全文
0 0
- 面试题3:二维数组中的查找
- 面试题3 二维数组中的查找
- 面试题3:二维数组中的查找
- 面试题3-二维数组中的查找
- 面试题3 二维数组中的查找
- 面试题3:二维数组中的查找
- 面试题3二维数组中的查找
- 面试题3:二维数组中的查找
- 面试题3 ----二维数组中的查找
- 面试题3:二维数组中的查找
- 面试题3:二维数组中的查找
- 面试题3:二维数组中的查找
- 面试题3:二维数组中的查找
- 面试题3:二维数组中的查找
- 面试题3:二维数组中的查找
- 面试题3:二维数组中的查找
- 面试题3:二维数组中的查找
- 面试题 3:二维数组中的查找
- 决策树
- POJ 2524--Ubiquitous Religious
- URAL 1002|Phone Numbers|动态规划
- codeforces 546E. Soldier and Traveling 网络流
- CorelDraw应该怎么样才能学好描图技巧看看这个就能懂
- 试题3:二维数组中的查找
- java中的访问权限
- Spark Streaming基于状态、窗口的实时数据流
- java中的多线程深入探究
- hdu 1019 Least Common Multiple 最小公倍数
- Spring中Bean及@Bean的理解
- (crm笔记2-1)struts2层与前端页面的连接
- jsp+Javabean+servlet实现修改
- 最短路,最小生成树,及拓扑排序模板整理