- import java.util.Scanner;
- //键盘录入一个偶数,输出其质数的和.<哥德巴赫猜想>
- public class Test5_Test {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入一个偶数");
- int a = sc.nextInt();
- for (int i = 2; i < a; i++) {
- for (int j = 2; j <= i; j++) {
- if (i + j == a) {
- if (found(i) && found(j)) {
- System.out.println(a + " = " + i + "+" + j);
- }
- }
- }
- }
- }
- public static boolean found(int i) {
- boolean b = true;
- for (int j = 2; j < i; j++) {
- b = b && (i % j != 0);
- }
- return b;
- }
- }
复制代码 |
|