title: Java: Permutation of array
body: <p>I'm not very familiar with recursion in Java. I'm trying to write a method that calculates all the permutations of an array of integers. I need to modify the following perfectly working method so that, instead of printing to screen all the permutations of an array, it inserts them in a bidimensional array. So the input of the method is the array of <em>n</em> integers and the output is a bidimensional array with <em>n!</em> rows and <em>n</em> columns. The program I need to modify is this:</p>
  
  <pre><code>public static void permute(int[] array, int k)
  {
      for(int i=k; i&lt;array.length; i++)
      {
          int temp;
          temp = array[i];
          array[i] = array[k];
          array[k] = temp;
          permute(array, k+1);
          int temp2;
          temp2 = array[i];
          array[i] = array[k];
          array[k] = temp2;
      }
      if (k == array.length-1)
      {
          Array.printValues(array);
      }
  }
  </code></pre>
  
  <p>So, what I need is something like this:</p>
  
  <pre><code>public static int[][] permute(int[] array, int k)
  {
      //code here
  }
  </code></pre>
  
  <p>Thank you.</p>