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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 374856298 中级黑马   /  2015-4-28 22:01  /  441 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

1.程序分析:利用for循环控制100-999个数,每个数分解出个位,十位,百位。  
public class exp2{
        public static void main(String args[]){
                int i=0;
                math mymath = new math();
                for(i=100;i<=999;i++)
                        if(mymath.shuixianhua(i)==true)
                        System.out.println(i);
        }
}
class math
{
        public int f(int x)
        {
                if(x==1 || x==2)
                        return 1;
                else
                        return f(x-1)+f(x-2);
        }
        public boolean iszhishu(int x)
        {
                for(int i=2;i<=x/2;i++)
                        if (x % 2==0 )
                                return false;
                return true;
        }
        public boolean shuixianhua(int x)
        {
           int i=0,j=0,k=0;
           i=x / 100;
           j=(x % 100) /10;
           k=x % 10;
           if(x==i*i*i+j*j*j+k*k*k)
                   return true;
           else
                   return false;
          
        }
}

6 个回复

倒序浏览
刚来。还不会打
回复 使用道具 举报
谢谢分享
回复 使用道具 举报
类的命名不规范吧。。。
回复 使用道具 举报
if(mymath.shuixianhua(i)==true) 其中 ==true可以去掉
回复 使用道具 举报
感觉有点冗余了
回复 使用道具 举报
gzp123 中级黑马 2015-4-28 22:38:45
7#
这下又让我受教了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马