/**
* 求n以内的质数
* @author zkx
* @Date 2021/9/8 10:54
*/
public class Demo1 {
public static void main(String[] args) {
int n = 100;
Demo1.getPrimeNumber(n);
}
public static void getPrimeNumber(int n){
for (int i = 1; i <= n; i++) {
for (int j = 2; j <= i; j++) {
// 2-(i-1)遍历 可除尽则跳出
if(i % j == 0 && j != i){
break;
}
// 遍历到i 打印
if(j == i){
System.out.print(i+ " ");
}
}
}
}
}
08-05
3484
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)