/**
* 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);
}
}
}
}
打印给定一字符串的所有字母组合——递归实现
最新推荐文章于 2024-11-04 16:04:55 发布