/*
求1000以内的质数
质数定义:只能被1或者自身整除的自然数(不包括1),称为质数。
*/
class Prime {
public static void main(String[] args) {
boolean flag = true;
int count = 0;
long start = System.currentTimeMillis();
for (int i = 2;i <= 1000 ;i++ ) {
for (int n = 2;n <= Math.sqrt(i) ;n++ ) {
if (i % n == 0) {
flag = false;
break;
}
}
if(flag == true){
count++;
}
flag = true;
}
long end = System.currentTimeMillis();
System.out.println(count);
System.out.println("time:" + (end - start));
}
}

创作不易 请尊重他人劳动成果,未经授权禁止转载!