-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHourGlassHR.java
More file actions
45 lines (43 loc) · 1.15 KB
/
Copy pathHourGlassHR.java
File metadata and controls
45 lines (43 loc) · 1.15 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
// 1 1 1 0 0 0
// 0 1 0 0 0 0
// 1 1 1 0 0 0
// 0 0 0 0 0 0
// 0 0 0 0 0 0
// 0 0 0 0 0 0
//The there are many hourglass but the one with most sum is
// 1 1 1
// 1
// 1 1 1
//Java Program to find out the hourglass with most sum
import java.util.*;
public class HourGlassHR
{
public static void main(String[] args)
{
int a[][] = new int[6][6];
int maxSum = Integer.MIN_VALUE;
try (Scanner scanner = new Scanner(System.in);)
{
for(int i = 0; i < 6; i++)
{
for(int j = 0; j < 6; j++)
{
a[i][j] = scanner.nextInt();
if (i > 1 && j > 1)
{
int sum =
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 (sum > maxSum) {maxSum = sum;}
}
}
}
}
System.out.println(maxSum);
}
}