java计算1到100以内所有质数的和

public static void test8() {
        int sum = 0;
        for (int m = 2; m <= 100; m++) {
            int x = 0;
            for (int n = 2; n < m; n++) {
                if (m % n == 0) {
                    x++;
                }
            }
            if (x == 0) {
                sum += m;
            }
        }
        System.out.print(sum);
    }

猜你喜欢

转载自blog.csdn.net/qq_34491508/article/details/81257619