• Source
    1. /* package whatever; // don't place package name! */
    2.  
    3. import java.util.*;
    4.  
    5. /* Name of the class has to be "Main" only if the class is public. */
    6. class Ideone
    7. {
    8. public static void main(String[] args){
    9. String s = "abcd";
    10. printPermutations(s, "");
    11. }
    12.  
    13. private static void printPermutations(String s, String t){
    14. if(s == null || s.length() == 0){
    15. System.out.println(t);
    16. return;
    17. }
    18.  
    19. for(int k=0; k<s.length(); k++){
    20. String target = t + s.charAt(k);
    21. printPermutations(s.substring(0,k)+s.substring(k+1), target);
    22. }
    23. }
    24. }
    25.