fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int [][] Matriz = new int [5][5];
  13. int [] diagonal = new int[5];
  14.  
  15. Matriz[0][0] = 1;
  16. Matriz[0][1] = 3;
  17. Matriz[0][2] = 6;
  18. Matriz[0][3] = 8;
  19. Matriz[0][4] = 7;
  20. Matriz[1][0] = 3;
  21. Matriz[1][1] = 7;
  22. Matriz[1][2] = 8;
  23. Matriz[1][3] = 0;
  24. Matriz[1][4] = 3;
  25. Matriz[2][0] = 2;
  26. Matriz[2][1] = 4;
  27. Matriz[2][2] = 3;
  28. Matriz[2][3] = 6;
  29. Matriz[2][4] = 7;
  30. Matriz[3][0] = 8;
  31. Matriz[3][1] = 9;
  32. Matriz[3][2] = 1;
  33. Matriz[3][3] = 3;
  34. Matriz[3][4] = 5;
  35. Matriz[4][0] = 5;
  36. Matriz[4][1] = 6;
  37. Matriz[4][2] = 7;
  38. Matriz[4][3] = 8;
  39. Matriz[4][4] = 5;
  40.  
  41. for(int i = 0; i<5; i++ ){
  42. diagonal[i] = Matriz[i][i];
  43. }
  44.  
  45. for(int i = 0; i<5; i++ ){
  46. Matriz[i][i] = diagonal[4-i];
  47. }
  48.  
  49. for(int i = 0; i<5; i++ ){
  50. for(int j=0; j<5; j++){
  51. System.out.print(Matriz[i][j]+" ");
  52. }
  53. System.out.println();
  54. }
  55. }
  56. }
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
5 3 6 8 7 
3 3 8 0 3 
2 4 3 6 7 
8 9 1 7 5 
5 6 7 8 1