-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy path2DArray.java
More file actions
26 lines (25 loc) · 783 Bytes
/
2DArray.java
File metadata and controls
26 lines (25 loc) · 783 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
import java.io.*;
import java.util.*;
import java.lang.*;
public class Solution {
public static void main(String[] args) throws IOException {
Scanner sc = 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] = sc.nextInt();
}
}
int max = Integer.MIN_VALUE;
int sum = 0;
for (int i = 1; i < 5; i++) {
for (int j = 1; j < 5; j++) {
sum = arr[i][j] + arr[i-1][j-1] + arr[i-1][j] + arr[i-1][j+1] + arr[i+1][j-1] + arr[i+1][j] + arr[i+1][j+1];
if(sum > max){
max = sum;
}
}
}
System.out.println(max);
}
}