title: How to calculate the average value of each column in 2D array?
body: <p>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.</p>
  <pre class="lang-java prettyprint-override"><code>static double average_columns(double matrix[][]) {
      int i, j, sum = 0, average = 0;
      for (i = 0; i &lt; matrix.length; i++) {
          for (j = 0; j &lt; matrix[i].length; j++) {
              sum = (int) (sum + matrix[i][j]);
          }
          average = sum / matrix[i].length;
          sum = 0;
      }
      return average;
  }
  </code></pre>