最小的质数为2,质数是除了1和它本身不被整除的数据
public class Test{
public static void main(String[] args){
// 求 1-100 之间所有的质数
// 1 既不是质数 也不是合数
// 质数 2 3 5 7 11 13 17 ...
// 除了1和本身没有其他数字整除
int count=0;
boolean flag=false;
outer:for(int i=2;i<=100;i++){
for(int j=2;j<=Math.sqrt(i);j++){
if(i%j==0){//i 和j 不相等 并且i%j==0 说明不是质数
continue outer;//取消其他对比 i进行下一个
}
}
count++;
System.out.print(i+" ");
}
System.out.println("一共:"+count);
}
}