-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_array.java
More file actions
48 lines (38 loc) · 1.21 KB
/
binary_array.java
File metadata and controls
48 lines (38 loc) · 1.21 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
import java.util.*;
public class binary_array {
public static void main(String[] args) {
/*
* we need to find the index where left , right, top, bottom values are 0''''
* rest are 1
*
*
*/
int i1 = 0;
int j1 = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of rows");
int row = sc.nextInt();
System.out.print("Enter the number of columns: ");
int column = sc.nextInt();
int [][] arr = new int[row][column];
for(int i = 0 ; i<row ; i++){
for(int j = 0;j<column;j++){
arr[i][j] = sc.nextInt();
}
}
// int [][] arr = {{0,1,1,0},{1,1,0,1},{0,1,1,0}};
for(int i=1 ; i<row-1;i++){
for(int j = 1;j<column-1;j++){
if(arr[i][j-1]==arr[i][j+1]
&& arr[i][j+1]==arr[i-1][j]
&& arr[i-1][j]== arr[i+1][j]
&& arr[i+1][j]== 1){
i1=i;
j1=j;
break;
}
}
System.out.printf("ANSER: %d, %d",i1,j1);
}
}
}