title: Generating permutations of an int array using java -- error
body: <p>I am writing a JAVA code to generate all permutations of a integer array.
  Though I am getting the number of permutations right, the permutations themselves are not correct.</p>
  
  <p>On running I obtain:</p>
  
  <pre><code>Input array Length
  3
  1
  2
  3
  0Permutation is
  1,  2,  3,  
  ##########################
  1Permutation is
  1,  3,  2,  
  ##########################
  2Permutation is
  3,  1,  2,  
  ##########################
  3Permutation is
  3,  2,  1,  
  ##########################
  4Permutation is
  1,  2,  3,  
  ##########################
  5Permutation is
  1,  3,  2,  
  ##########################
  6  number of permutations obtained
  BUILD SUCCESSFUL (total time: 3 seconds)
  
  
  public class PermulteArray {
  
      public static int counter = 0;
  
      public static void Permute(int[] input, int startindex) {
          int size = input.length;
  
          if (size == startindex + 1) {
              System.out.println(counter + "Permutation is");
              for (int i = 0; i &lt; size; i++) {
                  System.out.print(input[i] + ",  ");
              }
              System.out.println();
              System.out.println("##########################");
              counter++;
          } else {
              for (int i = startindex; i &lt; size; i++) {
  
                  int temp = input[i];
                  input[i] = input[startindex];
                  input[startindex] = temp;
                  Permute(input, startindex + 1);
              }
          }
      }
  
      public static void main(String[] args) {
          Scanner in = new Scanner(System.in);
          System.out.println("Input array Length");
          int arraylength = in.nextInt();
          int[] input = new int[arraylength];
          for (int i = 0; i &lt; arraylength; i++) {
              input[i] = in.nextInt();
          }
          counter = 0;
          Permute(input, 0);
          System.out.println(counter + "  number of permutations obtained");
      }
  }
  </code></pre>