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.
public class solution{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int [][]a = new int[6][6];
for(int i = 0; i<6; i++){
for(int j =0; j<6; j++){
a[i][j] = scan.nextInt();
}
}
System.out.println(findlarges(a));
}
public static int findlarges(int [][]a){
int largest = Integer.MIN_VALUE;
for(int i = 1; i<=4; i++){
for(int j = 1; j <=4; j++){
int sum = 0;
sum += a[i][j] + a[i+1][j-1] + a[i+1][j] + a[i+1][j+1]
+ a[i-1][j-1] + a[i-1][j] + a[i-1][j+1];
if(sum > largest){
largest = sum;
}
}
}
return largest;
}
}
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 →
this my code:
import java.io.; import java.math.; import java.security.; import java.text.; import java.util.; import java.util.concurrent.; import java.util.function.; import java.util.regex.; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList;
public class solution{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); int [][]a = new int[6][6]; for(int i = 0; i<6; i++){ for(int j =0; j<6; j++){ a[i][j] = scan.nextInt(); } }
}