/*
* 水仙花数(Narcissistic number)也被称为超完全数字不变数,
* 水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身
* 例如:1^3 + 5^3+ 3^3 =1 + 125 + 27 = 153,
* 水仙花数是指:一个三位数,其各位数字的立方和等于该数本身
*/
public class Demo05 {
public static void main(String[] args) {
int count = 0;
int i = 100;
while(i < 1000) {
int a = i / 100 % 10; //百位
int b = i / 10 % 10; //十位
int c = i % 10; //个位
if (i == a * a * a + b * b * b + c * c * c) {
System.out.println(" " + i + "是水仙花数");
count++;
}
i++;
}
System.out.println("一共有" + count + "个水仙花数");
}
}
/*输出结果:
*
* 153是水仙花数
* 370是水仙花数
* 371是水仙花数
* 407是水仙花数
* 一共有4个水仙花数
*
*/