-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch_In_2D_Array.java
More file actions
54 lines (40 loc) · 1.23 KB
/
Copy pathSearch_In_2D_Array.java
File metadata and controls
54 lines (40 loc) · 1.23 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package dsa;
import java.util.Arrays;
public class Search_In_2D_Array {
public static void main(String[] args) {
///Search In 2D Array
int[][] arr={{ 4,7,6 },
{ 14,5,8 },
{ 7,3,9 }};
int store=14;
int[] ans=arr(arr,store);
System.out.println(Arrays.toString(ans));
//Max num Search In 2D Array
int max=arr[0][0];
System.out.println(Maxarr(arr,max));
}
static int[] arr(int[][]arr,int store){
int ans=store;
int rem=0;
for (int i=0;i<arr.length;i++){
for (int j=0;j<i;j++){
if (ans==arr[i][j]){
return new int[]{i, j};
}
}
}
return new int[]{-1};
}
///////////////////////////////////////////////////////////////////////////////
static int Maxarr(int[][]arr,int store){
int ans=Integer.MIN_VALUE; // OR int ans=store;
for (int i=0;i<arr.length;i++){
for (int j=0;j<arr[i].length;j++){
if (ans<arr[i][j]){
ans=arr[i][j];
}
}
}
return ans;
}
}