How to calculate the average value of each column in 2D array?
问题 I am trying to calculate the average value of columns in 2D array, but I cannot figure out the code. The function should return the average value of each column. And I cannot print the result in the function. The print should be in main function. static double average_columns(double matrix[][]) { int i, j, sum = 0, average=0; for (i = 0; i < matrix.length; i++) { for (j = 0; j < matrix[i].length; j++) { sum=(int) (sum+matrix[i][j]); } average=sum/matrix[i].length; sum=0; } return average; }