您的位置:首页 > 其它

写出一个字符串,打印出字符串中字符的所有排序-递归

2016-03-19 22:33 399 查看
public static void main(String[] args) {
String str = "";

Scanner scan = new Scanner(System.in);

str = scan.nextLine();

permutation(str.toCharArray(), 0);
}

public static void permutation(char[] str, int i) {
if (i >= str.length)
return;
if (i == str.length - 1) {
System.out.println(String.valueOf(str));
} else {
for (int j = i; j < str.length; j++) {
char temp = str[j];
str[j] = str[i];
str[i] = temp;

permutation(str, i + 1);

temp = str[j];
str[j] = str[i];
str[i] = temp;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: