public class 水仙花数 {
public static void main(String[] args) {
System.out.println("100-999中水仙花数有:");
for (int i = 100; i < 1000; i++) {
int a = i % 10;
int b = i % 100 / 10;
int c = i / 100;
if (c * c * c + b * b*b + a*a*a ==i)
System.out.println("i=" + i + "百位是:" + c +
"十位是:" + b + "个位是:" + a);
}
}
}
100-999中水仙花数有:
i=153百位是:1十位是:5个位是:3
i=370百位是:3十位是:7个位是:0
i=371百位是:3十位是:7个位是:1
i=407百位是:4十位是:0个位是:7
Process finished with exit code 0