数SQRT(この数)を除去しながら、2、それぞれ割り切れるならば、これは素数とその逆、数が素数でないことを示す:方法素数を分析します。
package primeNumber;
public class TestDemo {
public static void main(String[] args) {
int count = 0;
//每次+2是为了去掉偶数,因为102是偶数
for(int i=101; i<200; i+=2) {
boolean b = false;
//判断一个正数是否是素数,只要用小于它的平方根的数整除它就可以了
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.println(i );
}
}
System.out.println( "素数个数是: " + count);
}
}