水仙花数
水仙花数
水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身(例如:1^3 + 5^3+ 3^3 = 153)。
public class waterFlowerNum {
public static void waterFlower() {
// 求出个、十、百的数字
for(int i=100;i<1000;i++) {
int g = i/1%10;
int s = i/10%10;
int b = i/100;
if(g*g*g + s*s*s + b*b*b==i) {
System.out.print(i + " ");
}
}
}
public static void main(String[] args) {
waterFlower();
}
}

浙公网安备 33010602011771号