title: Writing two dimensional array in java
body: <p>I have the following two dimensional array in my java program.  </p>
  
  <pre><code>Integer[][] arrayOfSets = {
          {1,2,5,6,9,10},
          {9,10,11,12},
          {1,2,3,4},
          {3,5,6,7,8},
          {9,10,11,12},
          {4,8},
  };
  </code></pre>
  
  <p>Can someone show me the code on how to make the program dynamic, where the program asks the user to enter the row number and column number, i.e. how many arrays the two dimensional array should hold and then asks the user for how big each array and what are the numbers that each array should hold?
  Thanks so much in advance.</p>
  
  <p>This is what I've tried so far:</p>
  
  <pre><code> System.out.println("HOw many sets arrays would you like");
      int numArrays=sc.nextInt();
      Integer [][] arrayName = new Integer[numArrays][];
      for(int i=0;i&lt;arrayName.length;i++){
          System.out.println("enter the size of the array number"+i);
          int sizeArray=sc.nextInt();
          for(int k=0;k&lt;sizeArray;k++){
              System.out.println("enter element");
              int e=sc.nextInt();
              arrayName[i][k]=e;
          }
  
      }
  </code></pre>
  
  <p>Does this look right? Thanks for all the help in advance.</p>
  
  <p>Ok I modified my cod again. Following is what I have now:</p>
  
  <p>System.out.print("How many arrays would you like?");
      int numSets=sc.nextInt();
      Integer[][] result = new Integer[numSets][];</p>
  
  <pre><code>for (int k=0; k&lt; numSets; k++){
    System.out.println("Enter the size of the array");
    int setSize  = sc.nextInt();
  
    Integer[] row = new Integer[setSize];
    for (int m=0; m&lt; setSize; m++){
        System.out.println("enter element: ");
        row[m] = sc.nextInt();
    }
    result[k] = row;
  }
  </code></pre>