所谓素数是指除了 1 和它本身以外,不能被任何整数整除的数,例如 11 就是素数,因为它不能被 2~10 的任一整数整除
public class Ex1 {
public static void main(String[] args) {
int num = 0;
int i;
int j;
//素数
for (i = 2; i <= 100; i++) {
for (j = 2; j < i; j++) {
if (i % j == 0) {
//不是素数,跳出内层循环
break;
}
}
if (j == i) {
num++;
System.out.println(i);
}
}
System.out.println("一共"+num);
}
}