求水仙花数

/**
     * 求水仙花数
     * @param left
     * @param right
     */
    static void checkFlowerNumber(int left,int right){
        for (int i = left; i <= right; i++) {
            char[] ch = (i+"").toCharArray();
            int sum = 0;
            int num = 0;
            for (int j = 0; j < ch.length; j++) {
                num = Integer.parseInt(ch[j]+"");
                sum += num*num*num;
            }
            if (sum == i) {
                System.out.println(i);
            }
        }
    }

 

posted @ 2016-02-16 15:36  phyxis_xu  阅读(134)  评论(0编辑  收藏  举报