java经典习题2

/*
题目:判断101-200之间有多少个素数,并输出所有素数。
*/
import java.lang.Math;

public class Class2 {

public static void main(String[] args) {
boolean a = false;
for(int i = 101; i <= 200; i++){
for(int j = 2; j <= Math.sqrt(i); j++){
if( i % j == 0){
a = false;
break;
}else{
a = true;
}
}
if(a == true){
System.out.println(i);
}
}

}

}

猜你喜欢

转载自www.cnblogs.com/zhuozige/p/12357881.html