package javademo;
public class text {
public static void main(String[] args) {
int count=0;
for (int i = 1; i < 200 ; i++) {
boolean flag=true;
for (int j = 2; j < i; j++) {
if (i%j==0){
flag=false;
break;
}
}
if (flag){
System.out.println("当前数字"+i+"是质数");
count++;
}
}
System.out.println("共有"+count+"个质数");
}
}
判断1-200有多少个质数,并打印所有质数
最新推荐文章于 2023-07-30 22:32:49 发布