-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwoDArrays.java
42 lines (31 loc) · 861 Bytes
/
TwoDArrays.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package hackerrank;
import java.util.Scanner;
public class TwoDArrays {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int sum,max = 0,n=6;
//int[][] arr = new int[6][6];
int arr[][] ={{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}};
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
//int arrItem = Integer.parseInt(arrRowItems[j]);
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
for(int i = 0;i<=n-3;i++)
{
for(int j = 0;j<=n-3;j++)
{ sum = 0;
for(int k = j;k<j+3;k++){
sum += arr[i][k]+arr[i+2][k];
}
sum += arr[i+1][j+1];
if(sum>max)
max = sum;
}
}
System.out.print(max +" ");
scan.close();
}
}