java 练习 打印出所有的 "水仙花数 ",所谓 "水仙花数 "是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个 "水仙花数 ",因为153=1的三次方+5的三次方+3的三次方。

package com.hanqi;

public class Text4 {

    public static void main(String[] args) {

        for (int num=100;num<1000;num++)
        {
            int gw=num%10;
            int sw=num/10%10;
            int bw=num/100%10;
            if (gw*gw*gw+sw*sw*sw+bw*bw*bw==num)
            {
                System.out.println(num);
            }
        }
    }

}

 

posted on 2016-05-08 20:17  煜渝  阅读(7543)  评论(0编辑  收藏  举报

导航