package com.heima.IO;
public class Day1_ClassTest2 {
public static void main(String[] args) {
print(8);
}
public static void print(int n) {
int a = 0;
int b = 0;
for (int i = n, j = 1; i >= 1; i--, j *= 10) {
a += i * j;
}
for (int i = 1, j = 1; i <= n; i++, j *= 10) {
b += i * j;
}
for (int i = a; i <= b; i++) {
int[] arr = new int[n];
int t = 0;
for (int j = i; j > 0; j /= 10) {
arr[t++] = j % 10;
}
if (compare(arr)) {
System.out.println(i);
}
}
}
public static boolean compare(int[] i) {
int[] i1 = new int[i.length];
for (int j = 1; j <= i.length; j++) {
i1[j - 1] = j;
}
int sum = 0;
for (int j = 0; j < i.length; j++) {
for (int j2 = 0; j2 < i1.length; j2++) {
if (i1[j2] == i[j]) {
sum++;
i1[j2] = -1;
}
}
}
if (sum == i.length) {
return true;
} else {
return false;
}
}
}
|