title: Find all permutations code Problem (Java)
body: <p>I wrote this code to find all possible permutations of some numbers. But i dosen't want to use one digit twice:<br>
  123,132,213 are OK, but it produces numbers like 122, 121 etc.<br>
  What am i doing wrong?</p>
  
  <pre><code>import java.util.HashSet;
  
  public class main {
  
  public static void main(String[] args) {        
  
      HashSet&lt;Integer&gt; l = new HashSet&lt;Integer&gt;();        
      for(int i=0;i&lt;=3;i++){
          l.add(i);
      }       
      perm(l,3,new StringBuffer());
  
  }
  
   static void perm(HashSet&lt;Integer&gt; in, int depth,StringBuffer out){             
      if(depth==0){
          System.out.println(out);
          return;
      }       
  
      int len = in.size();
      HashSet&lt;Integer&gt; tmp = in;
  
      for(int i=0;i&lt;len;i++){
          out.append(in.toArray()[i]);
          tmp.remove(i);
  
          perm(tmp,depth-1,out);
  
          out.deleteCharAt(out.length()-1);
          tmp.add(i);
      }
  }
  }
  </code></pre>