hacker rank java 27th problem(java 2d array)

28. java 2d array

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Solution {



    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int[][] a = new int[6][6];
 int max_sum =Integer.MIN_VALUE;
      int sum=0;
      for(int i=0;i<6;i++){
            for (int j = 0; j < 6; j++) {
       a[i][j] = scanner.nextInt();     
           
            }
      }
           
           
           
         for(int i=0;i<6;i++){
            for (int j = 0; j < 6; j++) {
              if(i<4&&j<4){
              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>max_sum){
        max_sum= sum;
      }
            }
         }
           
      System.out.println(max_sum);
    }
}


Compiler Message
Success
Input (stdin)Download
1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 0 2 4 4 0
0 0 0 2 0 0
0 0 1 2 4 0
{-truncated-}
Download to view the full testcase
Expected OutputDownload
19

Comments

Popular posts from this blog

Amazon Web Services

Hacker Rank all java and python problem solutions

Testing tools for React Apps