fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void permute(String str1,String str2){
  11. if(str2.length() != 0){
  12. char ch = str2.charAt(0);
  13. for(int i = 0; i <= str1.length();i++)
  14. permute(str1.substring(0,i) + ch + str1.substring(i,str1.length()),
  15. str2.substring(1,str2.length()));
  16. }else{
  17. System.out.println(str1);
  18. }
  19. }
  20. public static void main (String[] args) throws java.lang.Exception
  21. {
  22. // your code goes here
  23. permute("","1234");
  24. }
  25. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
4321
3421
3241
3214
4231
2431
2341
2314
4213
2413
2143
2134
4312
3412
3142
3124
4132
1432
1342
1324
4123
1423
1243
1234