求100-999的水仙花数 java 用while循环做

int a,b,c;
int x=100;
while (x<=999) {
a = x/100;
b = x%10/10;
c = x%10;

if (a*a*a+b*b*b+c*c*c==x) {
System.out.println("水仙花数we:"+x);
}
x++;
我觉得我的思路是对的啊,可是结果只出来一个407,求大神指点下我到底错在哪里了

int a, b, c;
int x = 100;
while (x <= 999) {
a = x / 100;
b = x / 10 % 10;//这里写错了,改成我这样
c = x % 10;

if (a * a * a + b * b * b + c * c * c == x) {
System.out.println("水仙花数we:" + x);
}
x++;
}

希望我的回答可以帮助你
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-03-02
b=x/10%10;

public class WaterFlower{
public static void main(String[] args){

int a,b,c;
int x=100;
while (x<=999) {
   a = x/100;
   b = x/10%10;
   c = x%10;
       
   if (a*a*a+b*b*b+c*c*c==x) {
System.out.println("水仙花数we:"+x);
   }
   x++;
}
}

}

本回答被网友采纳
相似回答