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) {
  11. int r=4;
  12. int col=4;
  13. int [][] mat = new int[r][col];
  14. int [] csums = new int[col];
  15. int [] rsums = new int[r];
  16. int rsum;
  17. for (int i = 0; i < mat.length; i++) {
  18. for (int j = 0; j < mat[i].length; j++) {
  19. mat[i][j]= (int)(Math.random()*10);
  20. csums[j] += mat[i][j];
  21. rsums[i] += mat[i][j];
  22. }
  23. }
  24. int sum=0;
  25. // Вывод матрицы
  26. for (int i=0; i < mat.length;i++,System.out.println())
  27. {
  28. for (int j=0;j < mat[i].length;j++){
  29.  
  30. System.out.print(mat[i][j]+" ");
  31. }
  32. System.out.print(rsums[i]);
  33. }
  34. for (int j=0;j < csums.length;j++){
  35.  
  36. System.out.print(csums[j]+" ");
  37. }
  38. }
  39. }
Success #stdin #stdout 0.09s 27816KB
stdin
Standard input is empty
stdout
6 5 0 8 19
0 8 0 5 13
7 8 8 7 30
5 3 7 7 22
18 24 15 27