Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

ft,用java写的,哪里错了

Posted by JLK at 2006-02-07 16:27:58 on Problem 2262
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        while(true)
        {
            Scanner cin=new Scanner(System.in);
            int a=cin.nextInt();
            if(a==0)return;
            for(int i=3;i<=a/2;i++)
            {
                if(isPrime(i)&&isPrime(a-i))
                {
                    System.out.println(a+" = "+i+" + "+(a-i));
                    break;
                }
            }
        }
    }
    
    public static boolean isPrime(int tmp)
    {
        if(tmp==3)return true;
        for(int i=2;i<=(tmp+1)/2;i++)
        {
            if(tmp%i==0)return false;
        }
        return true;
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator