//水仙花数字仅限三位数字,你可以先百度一下,四位数字也有类似规律那是4次方,
//称之为四叶玫瑰,这是刚写,输入想要求的位数即可!
public class Number {
public static void main(String[] args) {
init(4);// 输入几位数即可,比如:3,就是100--999,4:1000-9999
}
private static void init(int n) {
int x = (int) Math.pow(10, n - 1), y, count = 0;// 求界限!
for (int i = x; i < x * 10; i++) {
y = i;
int a = 0, tem;
for (int m = 0; y != 0; y /= 10) {// 循环取余!
m++;
tem = (int) (Math.pow(y % 10, n));
a += tem;
}
if (a == i) {
count++;
System.out.println(i);
}
}
System.out.println("符合规律共有:" + count + "个");
}
}