计算1000000以内的质数只用了398毫秒,闪电一样的速度.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16long start = System.currentTimeMillis();
for (int i = 1; i < 100; i++) {
double r = Math.sqrt(i);
for (int j = 2; j < r; j++) {
if(i % j == 0) {
break;
}else if( j > r )
{
System.out.println(i);
}
}
}
long end = System.currentTimeMillis();
System.out.println(end - start);