fork download
  1. public class Main
  2. {
  3. public static void main(String[] args)
  4. {
  5. int ilw = 5;
  6. int[][] tab = new int[ilw][ilw];
  7. int[] wiersze = new int[ilw];
  8. int[] kolumny = new int[ilw];
  9. for (int i = 0; i<ilw; i++)
  10. {
  11. for (int j=0; j<ilw; j++)
  12. {
  13. tab[i][j]=(int)(10*Math.random());
  14. wiersze[i]+=tab[i][j];
  15. kolumny[j]+=tab[i][j];
  16. }
  17. }
  18. System.out.printf("%6s%6d%6d%6d%6d%6d\n","",kolumny[0],kolumny[1],kolumny[2],kolumny[3],kolumny[4]);
  19. for(int i=0;i<ilw;i++)
  20. {
  21. System.out.printf("%6d%6d%6d%6d%6d%6d\n",wiersze[i],tab[i][0],tab[i][1],tab[i][2],tab[i][3],tab[i][4]);
  22. }
  23. }
  24. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
          22    24    17    21    25
    17     0     3     3     2     9
    22     4     7     2     7     2
    22     9     8     0     1     4
    16     0     0     9     5     2
    32     9     6     3     6     8