public class Main {
public static void main(String[] args) {
String s = "12345";
char[] c = s.toCharArray();
for (int i = 0; i < c.length; i++) {
char [] cc = new char[i+1];
for (int j = 0; j < cc.length; j++) {
cc[j] = c[j];
}
permutation(0,i,cc);
}
}
private static void permutation(int left, int right, char[] c) {
if(left == right){
System.out.println(new String(c));
}
for (int i = left; i <= right ; i++) {
swap(c,i,left);
permutation(left+1,right,c);
swap(c,i,left);
}
}
private static void swap(char[] c, int left, int right) {
char temp = c[left];
c[left] = c[right];
c[right] = temp;
}
}
09-17
766