A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© a820290471 中级黑马   /  2016-6-25 22:44  /  282 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

public class Prog3{
        public static void main(String[] args){
                for(int i=100;i<1000;i++){
                        if(isLotus(i))
                           System.out.print(i+" ");
                }
                System.out.println();
        }
        //判断水仙花数
        private static boolean isLotus(int lotus){
                int m = 0;
                int n = lotus;
                int sum = 0;
                m = n/100;
                n  -= m*100;
                sum = m*m*m;
                m = n/10;
                n -= m*10;
                sum += m*m*m + n*n*n;
                if(sum==lotus)
                        return true;
                else
                        return false;
                }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马