一个偶数总能表示为两个素数之和

import java.util.*;
public class Test{  
    public boolean isSuShu(int num){
        if(num==1) return false;
        if(num==2||num==3) return true;
        else{
            int i=2;
            for(;i<Math.sqrt(num);i++){
                if(num%i==0)
                break;
            }
            return i>Math.sqrt(num);
        }
    }
    public boolean isTrue(int num){
        boolean result = false;
        for(int i=2;i<=num;i++){
            if(isSuShu(i)&&isSuShu(num-i)){
                System.out.println(i+" + "+(num-i));
                result = true;
            }
        }
        return result;
    }
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int n=0;
        do{
        System.out.print("input n(n>5 and n%2=0): ");
        n=scan.nextInt();
        }while(n<6||n%2!=0);
        System.out.print("is true : "+new Test().isTrue(n));
    }
}
/*---运行结果---
    C:\>java Test
    input n(n>5 and n%2=0): 1
    input n(n>5 and n%2=0): 2
    input n(n>5 and n%2=0): 7
    input n(n>5 and n%2=0): 9
    input n(n>5 and n%2=0): 6
    3 + 3
    is true : true
    C:\>java Test
    input n(n>5 and n%2=0): 40
    3 + 37
    11 + 29
    17 + 23
    23 + 17
    29 + 11
    37 + 3
    is true : true
*/
原文地址:https://www.cnblogs.com/laoquans/p/2963348.html