输入两个数求其中的质数之和和个数
1 public static void susu() {
2 int count = 0, i, j, m, n, sum = 0;
3 System.out.println("请输入两个整数:");
4 Scanner in2 = new Scanner(System.in);
5 m = in2.nextInt();
6 n = in2.nextInt();
7 sum = 0;
8 count = 0;
9 if (m == 1 && n == 1) {
10 System.out.println("对不起,您的输入有误!");
11 }
12 for (j = m; j <= n; j++) {
13 int count2 = 0;// 用于判断每个数的因数是否为2
14 for (i = 1; i <= j; i++) {
15 if (j % i == 0) {
16 count2++;
17 }
18 }
19 if (count2 == 2) {
20 count++;
21 sum += j;
22 System.out.print(j + " ");
23 }
24 }
25 System.out.println();
26 System.out.println("count=" + count + ", sum=" + sum);
27 }