Adding up all the elements of each column in a 2d array
问题 So I have this dummy 2d array: int mat[][] = { {10, 20, 30, 40, 50, 60, 70, 80, 90}, {15, 25, 35, 45}, {27, 29, 37, 48}, {32, 33, 39, 50, 51, 89}}; I want to add up all the values by columns so it would add 10 + 15 + 27 + 32 and return 84 and so on. I have this so far: public void sum(int[][] array) { int count = 0; for (int rows = 0; rows < array.length; rows++) { for (int columns = 0; columns < array[rows].length; columns++) { System.out.print(array[rows][columns] + "\t"); count += array[0]