北京理工大学论坛

 找回密码
 注册(开放注册)
搜索
打印 上一主题 下一主题

[计算机类] 请JAVA高手指教

[复制链接]
跳转到指定楼层
1#
发表于 2006-6-1 22:46:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
JAVA高手帮我看一下这个程序有什么问题啊
这是:   
验证“哥德巴赫猜想”:任何大于6的偶数均可以表示为两个素数之和。
class yanss
{
   boolean yan(int x)
   {
           int s=0;
           for (int i=1;i<=x ;i++ )
           {  
                  if ((x%i)==0) s++;
           }
           if (s==2) return true;
   }
}
class test
{
        public static void main(String[] args)
        {
                int n=0;
                for (int a=8;a<=100 ;a +=2 )
                {
                        yanss ob=new yanss();
                                if (ob.yan(a)) n++;
                }
                if (n==47)  System.out.println("猜想正确啊!!");
        }
}
最后编绎出现这个错误:missing return statement
2#
发表于 2006-6-3 15:33:06 | 只看该作者

注意在if的另一种情况的返回值啊

class yanss
{
   boolean yan(int x)
   {
           int s=0;
           for (int i=1;i<=x ;i++ )
           {  
                  if ((x%i)==0) s++;
           }
           if (s==2) return true;
           
           return false;
   }
}
class test
{
        public static void main(String[] args)
        {
                int n=0;
                for (int a=8;a<=100 ;a +=2 )
                {
                        yanss ob=new yanss();
                                if (ob.yan(a)) n++;
                }
                if (n==47)  System.out.println("猜想正确啊!!");
        }
}
3#
 楼主| 发表于 2006-6-3 18:26:09 | 只看该作者

多谢了但还一个问题啊

这个程序好像还是错的啊
高手还能不能帮一下小弟啊
语法现在没有错了
您需要登录后才可以回帖 登录 | 注册(开放注册)

本版积分规则

手机访问本页请
扫描左边二维码
         本网站声明
本网站所有内容为网友上传,若存在版权问题或是相关责任请联系站长!
站长电话:0898-66661599    站长联系QQ:670427609   
         站长微信:hainanok
请扫描右边二维码
www.jtche.com

小黑屋|手机版|Archiver|北京理工大学论坛 ( 琼ICP备12002442号 )

GMT+8, 2024-4-27 00:07 , Processed in 0.037014 second(s), 16 queries .

Powered by 校园招聘信息

© 2001-2020 北京理工大学论坛校园招聘

快速回复 返回顶部 返回列表