代码如下:
public class MyWork { public static void main(String[] args) { System.out.println("100以内的质数如下:"); for (int num = 0; num <= 100; num++) { if (2 == num) { System.out.print(num + " "); continue; } for (int i = 2; i < num; i++) { if (0 == num % i) { break; } else if (i == num - 1 && 0 != num % i) { System.out.print(num + " "); } } } System.out.println(); } }