1000以内的所有的水仙花数
//4、求1000以内的所有的水仙花数。
//水仙花数:每个位上数字的立方==它本身。
import java.util.*;
public class WaterFigure
{
public static void main(String[] args)
{
int a,b,c,x;
for(x=100;x<1000;x++)
{
a=x/100;
b=x%100/10;
c=x%10;
if (x==a*a*a+b*b*b+c*c*c)
System.out.println("水仙花数为:"+x);
}
}
}
运行效果:

浙公网安备 33010602011771号