public class Demo3 {
private static final int N = 3;
public static void main(String[] args) {
char[] chs = { '1', '2', '3', '4' };
char[] cs = new char[N];
print(chs, N, cs, 0);
}
public static void print(char[] chs, int n, char[] cs, int count) {
if (count == N) {
System.out.println(new String(cs));
return;
}
for (int j = 0; j < chs.length; j++) {
if (!check(cs, chs[j])) {
cs[count] = chs[j];
print(chs, n, cs, count+1);
cs[count]=0;
} else {
continue;
}
}
}
public static boolean check(char[] chs, char c) {
for (char ch : chs) {
if (c == ch) {
return true;
}
}
return false;
}
}
|