Sort by

recency

|

677 Discussions

|

  • + 0 comments

    public class Solution {

    public static void main(String[] args) throws IOException {
             int sum;
        int maxsum = Integer.MIN_VALUE;
        int [][] a = new int[6][6];
        Scanner sc = new Scanner(System.in);
        for(int i=0; i<6; i++){
            for(int j=0; j<6; j++){
                a[i][j]=sc.nextInt();
            }
        }
            for (int i = 0; i < 6; i++) {
                for (int j = 0; j < 6; j++) {
                    if(i > 1 && j > 1) {
                        sum = a[i][j]
                                + a[i][j - 1]
                                + a[i][j - 2]
                                + a[i - 1][j - 1]
                                + a[i - 2][j]
                                + a[i - 2][j - 1]
                                + a[i - 2][j - 2];
                        if (sum > maxsum) {
                            maxsum = sum;
                        }
                    }
                }
            }
    

    //
    System.out.println(maxsum); } }

  • + 0 comments

    My solution is:

    int max = -100; for (int x=0;x<4;x++){ for (int y=0;y<4;y++){ int sum = 0; sum += arr.get(x).get(y); sum += arr.get(x).get(y+1); sum += arr.get(x).get(y+2); sum += arr.get(x+1).get(y+1); sum += arr.get(x+2).get(y); sum += arr.get(x+2).get(y+1); sum += arr.get(x+2).get(y+2); if (sum > max) max = sum;
    } } System.out.println(max);

  • + 0 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(); } }

        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;
    }
    

    }

  • + 0 comments

    Java 2D Array

    public class Solution { public static void main(String[] args) throws IOException { Scanner s= 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]=s.nextInt(); } } System.out.println(largestHourGlass(arr)); } public static int largestHourGlass(int[][] arr){ int largestHourGlass=Integer.MIN_VALUE; for (int i = 1; i <= 4; i++) { for (int j = 1; j <= 4; j++) {

                int sum = arr[i][j]+arr[i+1][j+1]+arr[i-1][j-1]+ arr[i+1][j-1]+arr[i-1][j+1]+arr[i-1][j]+arr[i+1][j];
                if(sum>largestHourGlass){
                    largestHourGlass=sum;
                }
            }
        }
        return largestHourGlass;
    }
        //Reduced Complexity and less calculations
    

    }

  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    
    public class Solution {
        public static void main(String[] args) throws IOException {
            Scanner s= 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]=s.nextInt();
                }
            }
            System.out.println(largestHourGlass(arr)); 
        }
        public static int largestHourGlass(int[][] arr){
            int largestHourGlass=Integer.MIN_VALUE;
            for (int i = 1; i <= 4; i++) {
                for (int j = 1; j <= 4; j++) {
                    
                    int sum = arr[i][j]+arr[i+1][j+1]+arr[i-1][j-1]+ arr[i+1][j-1]+arr[i-1][j+1]+arr[i-1][j]+arr[i+1][j];
                    if(sum>largestHourGlass){
                        largestHourGlass=sum;
                    }
                }
            }
            return largestHourGlass;
        }
    		//Reduced Complexity and less calculations
    }