forked from SedaKunda/hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2DArray.java
More file actions
40 lines (35 loc) · 1.03 KB
/
2DArray.java
File metadata and controls
40 lines (35 loc) · 1.03 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
/*
In this problem you have to print the largest sum among all the hourglasses in the array.
Input Format
There will be exactly lines, each containing integers seperated by spaces. Each integer will be between -9 and 9 inclusive.
Output Format
Print the answer to this problem on a single line.
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class 2DArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int arr[][] = new int[6][6];
for(int i=0; i < 6; i++){
for(int j=0; j < 6; j++){
arr[i][j] = in.nextInt();
}
}
int test = -100;
for (int a = 0; a < 4; a++) {
for (int b = 0; b < 4; b++) {
int count = 0;
count += arr[a][b] + arr[a][b+1] + arr[a][b+2] + arr[a+1][b+1] + arr[a+2][b]
+ arr[a+2][b+1] + arr[a+2][b+2];
if (count > test) {
test = count;
}
}
}
System.out.println(test);
}
}