forked from regression1607/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch2dArray.java
More file actions
35 lines (26 loc) · 772 Bytes
/
search2dArray.java
File metadata and controls
35 lines (26 loc) · 772 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
30
31
32
33
34
35
class search2dArray {
public static void main(String [] args){
// creating a 2d array
int[][] array1 = {
{1,2,3,4,5},
{20,13,24,67 },
{76,101, 167,277,87}
};
int target = 167;
System.out.println("Searching the target in the given 2d array");
System.out.println(maxSearch(array1,target));
}
static boolean maxSearch(int[][]arr,int target){
if(arr.length==0){
return false;
}
for(int i = 0 ; i<arr.length;i++){
for(int j = 0;j<arr[i].length ;j++){
if(arr[i][j]==target){
return true;
}
}
}
return false;
}
}