求1到100之间的素数(能被1和他本身整除的数)

// 5.求1到100之间的素数(能被1和他本身整除的数)

public static void Test5() {
    System.out.println("1到100之间的素数有:");
    for (int i = 2; i <= 100; i++) {
        int count = 0;
        for (int j = 2; j <= (Math.sqrt(i) + 1); j++) {
            if (i % j == 0) {
                count++;
            }
        }

        if (count == 0) {
            System.out.print(i + " ");
        }

    }

}
原文地址:https://www.cnblogs.com/MountDa/p/5831751.html