Created
December 22, 2016 04:15
-
-
Save NaotoKumagai/b8a22a6653a7dd4e3fda48159524104e to your computer and use it in GitHub Desktop.
Day 11: 2D Arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
import java.text.*; | |
import java.math.*; | |
import java.util.regex.*; | |
public class Solution { | |
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 ans = -2147483648; | |
for (int i = 0; i < 4; i++) { | |
for (int j = 0; j < 4; j++) { | |
int sumCell = sumCell(arr, i, j); | |
if (ans < sumCell) { | |
ans = sumCell; | |
} | |
} | |
} | |
System.out.print(ans); | |
} | |
private static int sumCell(int[][] arr, int i, int j) { | |
return 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]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment