How to find All Possible Combination(permutation) of a Word of same length in java

How to find All Possible Combination(permutation) of a Word of same length in java.
SOURCE : PermutationString.java

public class PermutationString {

public static void main(String[] args) {

String str = "aba";

PermutationString pm = new PermutationString();
pm.permutation(str);

}

private void permutation(String str) {
permutation(" ", str);

}

private void permutation(String prefix, String str) {

int n = str.length();

if (n == 0) {
System.out.println(prefix);
}

else {
for (int i = 0; i < n; i++) {
permutation(prefix + str.charAt(i),
str.substring(0, i) + str.substring(i + 1, n));
}
}

}

}


INPUT

aba

aba
aab
baa
baa
aab
aba

OUTPUT

number is perfect






Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment