北京理工大学论坛
标题:
请JAVA高手指教
[打印本页]
作者:
光辉岁月
时间:
2006-6-1 22:46
标题:
请JAVA高手指教
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
作者:
xiaohui20031984
时间:
2006-6-3 15:33
标题:
注意在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("猜想正确啊!!");
}
}
作者:
光辉岁月
时间:
2006-6-3 18:26
标题:
多谢了但还一个问题啊
这个程序好像还是错的啊
高手还能不能帮一下小弟啊
语法现在没有错了
欢迎光临 北京理工大学论坛 (http://www.bitbbs.cn/)
Powered by Discuz! X3.3