您的位置:首页 > 其它

判断101-200之间有多少个素数,并输出所有素数。

2017-05-22 17:16 344 查看
public static void main(String[] args) {
// TODO Auto-generated method stub

//判断101-200之间有多少个素数,并输出所有素数。
//素数:只能被1和他自身整除的的数
int count = 0;//用来统计素数的个数
for (int i = 101; i <= 200; i++) {
boolean b = false;
//Math.sqrt(double a)方法:返回正确舍入的 double 值的正平方根。
for (int j = 2; j <Math.sqrt(i); j++) {
if(i%j==0){
b = false;
break;
}else{
b = true;
}
}
if(b==true){
count++;
System.out.print(i+" ");
}
}

System.out.println("\n"+"素数的个数为:"+count+"个");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐