【发布时间】:2011-05-01 12:02:54
【问题描述】:
我想打印所有 2 位长的素数。这是我的代码:
for(int input = 11; input <= 99; input += 2){
for(int x = 2; x < (int)Math.sqrt(input) + 1; x++){
if(input%x != 0){
System.out.println(input);
break;
}else{
break;
}
}
}
问题在于它会打印出像 35 或 49 这样不是素数的数字。
【问题讨论】:
-
可能与您的问题无关,但是这两个
break语句似乎是多余的。 -
这个调试起来很简单,为什么不用调试器呢?