We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
`java
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
List<List<Integer>> arr = new ArrayList<>();
IntStream.range(0, 6).forEach(i -> {
try {
arr.add(
Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
.map(Integer::parseInt)
.collect(toList())
);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
bufferedReader.close();
List<Integer> results = new ArrayList<>();
for (int i = 0; i < 4; i++){
for (int j = 0; j < 4; j++){
results.add(SumQuad(i,j,arr));
}
}
System.out.println(Collections.max(results));
}
public static int SumQuad(int line, int colum,List<List<Integer>> list){
int total = 0;
for (int i = line; i < 3+line; i++){
for (int j = colum; j < 3+colum; j++){
if (!(i == line+1 && (j == colum || j == colum+2))) total += list.get(i).get(j);
}
}```
return total;
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java 2D Array
You are viewing a single comment's thread. Return to all comments →
`java public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
}