编一个程序,用for循环找到100到999之间的水仙花数,用java

如题所述

/*
1,for循环,找出100-999之间的水仙花数
(三位数: 个位数立方+十位数立方+百位数立方=原数)
*/
class Ex1{
public static void main(String []args){
for(int x=100; x<=999; x++){
//把x中的每一位都截出来
int a=x/100;//最高位
int c=x%10;//最低位
int b=x/10%10;//中间位
if(a*a*a+b*b*b+c*c*c==x){
System.out.print("x="+x+" ");
}
}

}
}
温馨提示:答案为网友推荐,仅供参考
相似回答