Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public static void main(String[] args) {
  2.  
  3. int[][] arr = new int[10][10];
  4. Random random = new Random();
  5.  
  6. for (int i = 0; i < 10; i++) {
  7. for (int j = 0; j < 10; j++) {
  8. arr[i][j] = random.nextInt();
  9. }
  10. }
  11.  
  12. int[][] sumarr = new int[10][10];
  13. int max = 0;
  14.  
  15. for (int i = 0; i < 10; i++) {
  16. for (int j = 0; j < 10; j++) {
  17.  
  18. if (i > 0 && i < 9) {
  19. sumarr[i][j] += arr[i-1][j] + arr[i+1][j];
  20. } else if (i == 0) {
  21. sumarr[i][j] += arr[i+1][j];
  22. } else if (i == 9) {
  23. sumarr[i][j] += arr[i-1][j];
  24. }
  25.  
  26. if (j > 0 && j < 9) {
  27. sumarr[i][j] += arr[i][j-1] + arr[i][j+1];
  28. } else if (i == 0) {
  29. sumarr[i][j] += arr[i][j+1];
  30. } else if (i == 9) {
  31. sumarr[i][j] += arr[i][j-1];
  32. }
  33. if (sumarr[i][j] > max) {
  34. max = sumarr[i][j];
  35. }
  36. }
  37. }
  38.  
  39. System.out.println(max);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement