/**
* Print all the permutation of a string
* @author Jeff
*/
public class test {
public static void main(String[] args) {
String str = "abcde";
new test().printAllPermutates(str);
}
public void printAllPermutates(String str) {
printAllPermutates(str, "");
}
public void printAllPermutates(String str, String preStr) {
if (str.length() == 0) {
System.out.println(preStr);
} else {
for (int i = 0; i < str.length(); ++i) {
printAllPermutates(str.substring(1), preStr + str.charAt(0));
str = str.substring(1) + str.charAt(0);
}
}
}
}
打印给定一字符串的所有字母组合——递归实现
最新推荐文章于 2019-09-14 23:05:00 发布