Untitled
unknown
java
a year ago
764 B
3
Indexable
class HelloWorld { public static boolean search(int arr[][],int key){ int row=arr.length-1;int col=0; while(row>=0 && col<=arr[0].length-1){ if(arr[row][col]==key){ System.out.println(arr[row][col]+" found at ("+row+","+col+")"); return true; } else if(arr[row][col]>key){ row--; } else{ col++; } } System.out.println("not found"); return false; } public static void main(String[] args) { int arr[][]={ {10,11,12,13},{15,17,19,20},{22,24,25,26},{30,32,34,35} }; int key=13; search(arr,key); } }
Editor is loading...
Leave a Comment