forked from rajatgoyal715/Hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayDS2D.java
More file actions
25 lines (23 loc) · 807 Bytes
/
ArrayDS2D.java
File metadata and controls
25 lines (23 loc) · 807 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
import java.util.Scanner;
public class ArrayDS2D {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a[][] = new int[6][6];
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
a[i][j] = sc.nextInt();
}
}
int max = a[0][0] + a[0][1] + a[1][1] + a[0][2] + a[2][0] + a[2][1] + a[2][2];
int hourglass;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
hourglass = a[i][j] + a[i][j + 1] + a[i][j + 2] + a[i + 1][j + 1] + a[i + 2][j] + a[i + 2][j + 1]
+ a[i + 2][j + 2];
if (hourglass > max)
max = hourglass;
}
}
System.out.println(max);
}
}