计算100~999之间的水仙花数

水仙花数是一个三位数,且个位,十位和百位的数的立方等于这个数本身的值。
代码如下:

/**
 * 求100-999水仙花数
 *
 */
public class Flower {
    public static void main(String[] args) {

        for(int i=100;i<1000;i++){
            int a=i%10;      //求个位上的数
            int b=i%100/10;   //求十位上的数
            int c=i/100;     //求百位上的数
            if(i==Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3)){
                System.out.println(i);
            }
        }
    }
}

你可能感兴趣的:(java)