fork download
  1. import java.util.Arrays;
  2.  
  3. public class Main {
  4. // ForExercises
  5.  
  6. public static void main (String[] args) {
  7. int[][] array = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};
  8.  
  9. System.out.println(Arrays.toString(array[0]));
  10. System.out.println(Arrays.toString(array[1]));
  11. System.out.println(Arrays.toString(array[2]));
  12. System.out.println(Arrays.toString(array[3]));
  13.  
  14. int sum = 0;
  15. int length = array[0].length;
  16. int height = array.length;
  17. System.out.println(length);
  18. System.out.println(height);
  19.  
  20.  
  21. for (int i = 0; i < length; i++) {
  22. for (int j = 0; j < height; j++) {
  23. sum = sum + array[j][i];
  24. }
  25. }
  26.  
  27. System.out.println("Sum = " + sum);
  28. }
  29. }
Success #stdin #stdout 0.09s 53556KB
stdin
Standard input is empty
stdout
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
[10, 11, 12]
3
4
Sum = 78