title: Use int 2d array to count char array in Java
body: <p>I didn't finish it yet, the question in named getRows() metthod, I just try use a int [][]counts to count how much X in char [][] array every rows, and print it out. I did something wrong, there isnt work.</p>
  
  <pre><code>package labassignment6;
  
  import java.util.Random;
  
  public class LabAssignment6 {
  
      public static void main(String[] args) {
          int size;
          char array[][];
          Random randy = new Random();
  
          for (size = 4; size &lt;= 6; size++) {
              //fill the array with random X O or space
              array = fillArray(size, randy);
  
              //print array
              System.out.println("\nsize" + size);
              printArray(array);
  
              doRows(array);
  //            1.method to doRows which call
  //                -method with loops to count X and Os in each row
  //                -methos print each row's counts
              //doColumns(array);
  //            2.method to doColumns which call
  //                -method with loops to count per column
  //                -method to print each column's counts
              //doDiagonals(array);
  //            3.method to doDiagonals which calls
  //                -method with single loop to count top left to bottom right and
  //                    another sigle loop to count top right to bottom left
  //                -method to print diagonal's counts
  
          }//end outer array size loop
  
      }
  
      public static char[][] fillArray(int size, Random randy) {
          int row = 0, col = 0, N;
          char i = ' ';
          char array[][];
          // create array
          array = new char[size][size];
          //code inside loops to choose X, O or space with weighting
  
          for (row = 0; row &lt; size; row++) {
              for (col = 0; col &lt; size; col++) {
                  N = randy.nextInt(5);
                  if (N == 0 || N == 1) {
                      i = 'X';
                  } else if (N == 2 || N == 3) {
                      i = 'O';
                  } else {
                      i = ' ';
                  }
                  array[row][col] = i;
              }
              System.out.println();
          }
  
          return array;
      }
  
      public static void printArray(char array[][]) {
          int row, col;
          for (row = 0; row &lt; array.length; row++) {
              for (col = 0; col &lt; array[row].length; col++) {
                  System.out.print(array[row][col] + " ");
              }
              System.out.println();
          }
  
      }
  
      public static void doRows(char array[][]) {
          int counts[][];
          //counts = new int [0][2];
          counts = new int[array.length - 1][array.length - 1];
          getRows(array, counts);
  //    printRows(array, counts);
      }
  
      public static void getRows(char array[][], int counts[][]) {
  //        int x = 0, o = 0, s = 0;
          for (int i = 0; i &lt; array.length; i++) {
              for (int j = 0; j &lt; array[0].length; j++) {
                  if (i&lt;array[j].length &amp;&amp; array[i][j] == 'X') {
                      counts[i][0]++;
                  }
              }
          }
          for (int i = 0; i &lt; array.length; i++) {
              System.out.println("Row " + i + " has " + counts[i][1] + " X");
  
          }
      }
  </code></pre>