title: Add the individual columns and rows in a 2D Array and display in a 1D Array table?
body: <p>I'm a beginner in Java programming. I have created the 2D array that generates random numbers to fill the array. </p>
  
  <p>But now I need to calculate the sum of the rows and columns individually and store the values in a separate table formatted in a 1D array using a method...</p>
  
  <p>This is what I have so far: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import java.util.*;
  import java.math.*;
  
      public class Q42 {
  
   public static void main(String[] args) {
  
    //create the grid
    final int rowWidth = 4;
    final int colHeight = 5;
  
    Random rand = new Random();
  
    int [][] board = new int [rowWidth][colHeight];
  
    //fill the grid
    for (int row = 0; row &lt; board.length; row++) {
     for (int col = 0; col &lt; board[row].length; col++) {
      board[row][col] = rand.nextInt(10);
     }
    }
  
    //display output
    for(int i = 0; i &lt; board.length; i++) {
     for(int j = 0; j &lt; board[i].length; j++) {
      System.out.print(board[i][j] + " ");
      //System.out.println();
     }
     System.out.println();
    
  } //end of main
  
   public static int[] sumTableRows(int[][] table)
   {
       int rows = table.length;
       int cols = table[0].length;
  
       int[] sum = new int[rows];
       for(int x=0; x&lt;rows; x++)
           for(int y=0; y&lt;cols; y++)
               sum[x] += table[x][y];
       return sum;     
   }
  
      } //end of class Main</code></pre>
  </div>
  </div>
  </p>