public class Test01{
public static void main(String[] args){
int count=0;
for(int i=101;i<=200;i++){
for(int j=2;j<=(int)Math.sqrt(i);j++){
if(i%j==0){
break;
}
if(j==(int)Math.sqrt){
count++;
System.out.println(i);
}
}
}
System.out.println("素数的个数是:"+count);
}
}
本文介绍了一个用于找出101到200之间所有素数的Java程序。通过使用双重for循环,结合数学方法Math.sqrt来优化素数检测过程,提高了算法效率。程序还输出了素数总数。
3万+

被折叠的 条评论
为什么被折叠?



