class TestPrinmeNumber {
public static void main(String[] args) {
boolean flag= false;
long start = System.currentTimeMillis();
for(int i = 2;i <=100000;i++){//实现100以内的循环
for(int j=2; j < Math.sqrt(i);j++){//优化3
if(i % j==0){
flag = true;
break;//加了一个break 优化1
}
}
if(!flag){//优化2
System.out.println(i);
}
flag = false;
}
long end = System.currentTimeMillis();
System.out.println("所花费的时间为" +(end - start));//1340
}
}
转载于:https://blog.51cto.com/9815936/1600713