水仙花数是指一个 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();
}
}
for(int i = 1; i < 1000; i++){
int j1 = i / 1 % 10;
int j2 = i / 10 % 10;
int j3 = i /100 % 10;
if(j1 * j1 * j1 + j2 * j2 * j2 + j3 * j3 *j3 == i){
System.out.println(i + "是水仙花数");
}
}