title: 2D array and its transpose
body: <p>so i just finished my program but the problem is every time i enter the elements i want my array to be for example if i enter a 3X2 array it prints out a 3X3 array and its transpose. now it works great except that when it outputs the correct output i get an outof bounds error at the end of the output.</p>
  
  <pre><code>import java.util.Random;
  import java.util.Scanner;
  
  
  public class Prog2c {
  
      public static void main(String[] args)
      {
          Scanner in = new Scanner(System.in);
          int userChoice;
          int userChoice2;
  
  
  
          System.out.println("Program 2c, Christian Villa, masc1854");
          System.out.print("please enter the first dimension of your array: ");
          userChoice = in.nextInt();
          System.out.print("Please enter the second dimension of your array: ");
          userChoice2 = in.nextInt();
  
  
  
          int[][] list = randArray(userChoice,userChoice2);
          printList(list);
  
  
  
          if(list.length &gt; 0)
          {
              for(int i = 0; i &lt; list.length; i++)
              {
                  for(int j = 0; j &lt; list.length; j++)
                  {
                      System.out.print(list[j][i] + "  ");
                  }
                  System.out.println();
              }
          }
  
      }
  
  
      /*--------------------------------------------------------------
      Method name: randArray
      Description: Creates a random array of n number of elements that is assigned by the user
      input:    a double array
      Output:        none
      Returns:      a randomly generated array 
      ----------------------------------------------------------------
      */
      public static int[][] randArray(int userChoice,int userChoice2)
      {
          int[][] list = new int[userChoice][userChoice2];
          Random random = new Random();
          for(int i = 0; i &lt; userChoice; i++)
              for(int j = 0; j &lt; userChoice2; j++)
          {
                 list[i][j] = random.nextInt((99-10)+1)+10; 
          }
          return list;
       }
      /*--------------------------------------------------------------
      Method name: printList
      Description: Prints the contents of an integer 2D array.
      input:    an integer 2D array
      Output:       display an integer 2D array
      Returns:      none
      ----------------------------------------------------------------
      */
      public static void printList(int[][] list)
      {
          for(int i = 0; i &lt; list.length; i++)
          {
              for(int j = 0; j &lt; list.length; j++)
              {
                  System.out.print(list[i][j]);
                  System.out.print("  ");
              }
              System.out.println();
          }
          System.out.println();
      }
  
  }
  </code></pre>