- public class sushu1dao100 {
- public static void main(String[] args) {
- int count1 = 0;
- for (int i = 2; i <= 100; i++) {
- int count2 = 0; // 内部循环结束后count2必须清零;
- for (int j = 1; j <= i; j++) {
- if (i % j == 0) {
- count2++;
- }
- }
- if (count2 > 2) {
- continue;
- } else {
- count1++;
- System.out.print(i + " ");
- }
- if (count1 % 5 == 0) {
- System.out.println();
- }
- }
- System.out.println("1-100之间的所有素数的个数为" + count1 + "个");
- }
- }
复制代码 |