All possible Angram String combinations in java [closed]

Check this one:

public class Test {
        public static void main(String[] args) {
           String input = "Wolf";
            permutation(input, "");
        }    
        private static void permutation(String input, String sofar) {
            if (input.equals("")) {
                System.out.printf("%s,", sofar);
            }
            for (int i = 0; i<input.length(); i++) {
                char c = input.charAt(i);
                if (input.indexOf(c, i + 1) != -1)
                continue;
                permutation(input.substring(0, i) + input.substring(i + 1), sofar+c);
            }
        }
}

Output:

Wolf,Wofl,Wlof,Wlfo,Wfol,Wflo,oWlf,oWfl,olWf,olfW,ofWl,oflW,lWof,lWfo,loWf,lofW,lfWo,lfoW,fWol,fWlo,foWl,folW,flWo,floW

Browse More Popular Posts

Leave a Comment