Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- int[][] arr = new int[10][10];
- Random random = new Random();
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- arr[i][j] = random.nextInt();
- }
- }
- int[][] sumarr = new int[10][10];
- int max = 0;
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- if (i > 0 && i < 9) {
- sumarr[i][j] += arr[i-1][j] + arr[i+1][j];
- } else if (i == 0) {
- sumarr[i][j] += arr[i+1][j];
- } else if (i == 9) {
- sumarr[i][j] += arr[i-1][j];
- }
- if (j > 0 && j < 9) {
- sumarr[i][j] += arr[i][j-1] + arr[i][j+1];
- } else if (i == 0) {
- sumarr[i][j] += arr[i][j+1];
- } else if (i == 9) {
- sumarr[i][j] += arr[i][j-1];
- }
- if (sumarr[i][j] > max) {
- max = sumarr[i][j];
- }
- }
- }
- System.out.println(max);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement