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++) {
swap(str,i,j);
permutation(str, i + 1);
swap(str,i,j);
}
}
}
public static void swap(char []str,int from ,int to){
char temp =str[from];
str[from]=str[to];
str[to]=temp;
}
//测试如下
public static void main(String [] args){
permutation("1234".toCharArray(),0);
}