-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHourGlassSum.java
More file actions
31 lines (29 loc) · 988 Bytes
/
HourGlassSum.java
File metadata and controls
31 lines (29 loc) · 988 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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class HourGlassSum {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int arr[][] = new int[6][6];
// User Input: There are 6 lines of input, where each line contains 6 space-separated integers describing 2D Array of 6x6.
for(int i=0; i < 6; i++){
for(int j=0; j < 6; j++){
arr[i][j] = in.nextInt();
}
}
// The input array has 16 hourglasses in it. Find the sum of all.
int[] sum = new int[16];
int k=0;
for(int i=0; i < 4; i++){
for(int j=0; j < 4; j++){
sum[k] = arr[i][j]+arr[i][j+1]+arr[i][j+2]+arr[i+1][j+1]+arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2];
k++;
}
}
// Find the maximum sum.
Arrays.sort(sum);
System.out.print(sum[15]);
}
}