• + 0 comments

    import java.util.*;

    public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[][] arr = new int[6][6];

        // Reading 6x6 array
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 6; j++) {
                arr[i][j] = sc.nextInt();
            }
        }
    
        int maxSum = Integer.MIN_VALUE; // To handle negative numbers too
    
        // Loop through possible hourglass centers
        for (int i = 1; i < 5; i++) {
            for (int j = 1; j < 5; j++) {
                int sum = arr[i][j]                // middle
                        + arr[i-1][j-1] + arr[i-1][j] + arr[i-1][j+1] // top
                        + arr[i+1][j-1] + arr[i+1][j] + arr[i+1][j+1]; // bottom
    
                maxSum = Math.max(maxSum, sum);
            }
        }
    
        System.out.println(maxSum);
    }
    

    }