-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch2DArray.java
More file actions
29 lines (28 loc) · 832 Bytes
/
Search2DArray.java
File metadata and controls
29 lines (28 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.*;
public class Search2DArray {
public static void Search(int arr[][],int key) {
for(int i=0;i<arr.length;i++){
for(int j=0;j<arr[0].length;j++){
if (arr[i][j]==key){
System.out.println(key+" is Found at"+"("+i+","+j+")");
}
}
}
System.out.println("Not Found!!");
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int row=sc.nextInt();
int col=sc.nextInt();
int array[][]=new int[row][col];
// Taking Input
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
array[i][j]=sc.nextInt();
}
}
int searchElement=sc.nextInt();
Search(array, searchElement);
sc.close();
}
}