找出n以内的质数
/**
* @des 找出n以内的质数 20
* 2 3 5 7 9 11 13 15 17 19
* @param n
*/
private static void print(int n) {
if (n<2){
return;
}
System.out.print("2 ");
for (int i = 3; i < n; i++) {
if (i%2==0){
continue;
}
boolean f = true;
for (int j = 3; j < (int)Math.sqrt(i); j++) {
if (i%j==0){
f = false;
break;
}
}
if (f){
System.out.print(i+" ");
}
}
System.out.println();
}

浙公网安备 33010602011771号