水仙花数:每一位上的数字是其自身的三次幂之和。
例如:153=1^3+5^3+3^3
public class Demo01 {
public static void main(String[] args) {
daffodilNumber();
}
public static void daffodilNumber() {
//遍历所有的水仙花数
for(int i = 100;i <= 999;i++) {
//分别计算出每个三位数的个位十位百位
int a = i/100;
int b = i/10%10;
int c = i%10;
if(i==((a*a*a)+(b*b*b)+(c*c*c))) {
System.out.println(i);
}
}
}
}
输出结果:153
370
371
407