方法①
public class JavaTest {public static void main(String[] args) {Label1: for (int i = 2;i < 100;i++){for (int j = 2;j < i;j++){if (i % j == 0){continue Label1;}};System.out.println(i);}}
}
方法②
public class JavaTest {public static void main(String[] args) {boolean judge = false;for (int i = 2;i < 100;i++){for (int j = 2;j < Math.sqrt(i);j++){if (i % j == 0){judge = false;break;}else {judge = true;}};if (judge){System.out.println(i);}}}
}
只需更改100就能改变更多数的输出。