Untitled

mail@pastecode.io avatar
unknown
java
a month ago
744 B
1
Indexable
Never
class HelloWorld {
    public static boolean search(int arr[][],int key){
            int row=0;int col=arr[0].length-1;
            while(row<arr.length && col>=0){
                if(arr[row][col]==key){
                    System.out.println(arr[row][col]+" found at ("+row+","+col+")");
                    return true;
                }
                else if(arr[row][col]>key){
                    col--;
                    
                }
                else{
                    row++;
                }
            }
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=32;
search(arr,key);
    }
}
Leave a Comment