public static void main(String[] args) {
for (int x = 2; x < 100; x++) {
boolean flag = true;
for (int y = 2; y <= (x+1)/2; y++) {
if (x%y == 0) {
flag = false;
}
}
if (flag) {
System.out.println(x+" ");
}
}
}
试试这个
public static void main(String[] args) {
n: for (int x = 2; x < 100; x++) {
for (int y = 2; y <= (x+1)/2; y++) {
if (x%y == 0) {
continue n;
}
}
System.out.println(x+" ");