java

打印出所有的水仙花数

所谓的水仙花数是指一个三位数,其各位数字立方和等于该数本身。
例如:153是一个已知的水仙花数,153=1^3+5^3+3^3

1
2
3
4
5
6
7
8
9
10
11
12
13
public class  {
public static void main(String[] args) {
for (int i = 100; i <= 999; i++) {
int h = i / 100;
int t = i % 100 / 10; //十位
int b = i % 100; //个位
int temp = (h * h * h) + (t * t * t) + (b * b * b);
if (i == temp) {
System.out.println(i);
}
}
}
}

————–3/50————–