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

帮我看看 java的 为什么会runtime error啊

Posted by yanical at 2006-07-24 13:37:10 on Problem 1047
import java.util.*;
import java.io.*;
import java.math.*;
public class RoundandRoundWeGo 
{
	public static void main(String[] args) throws Exception
	{
		BufferedReader sr=new BufferedReader(new InputStreamReader(System.in));
		String line;
		while(true)
		{
			line=sr.readLine();
			BigInteger input=new BigInteger(line);
			BigInteger output;
			String b;
			int length=line.length();
			int tag=1;
			if(input.compareTo(new BigInteger("0"))!=0)
			{
				for(int i=1;i<=length;i++)
				{
					output=input.multiply(new BigInteger(Integer.toString(i)));
					b=output.toString();
					if(!judge(line,b)) tag=0;
				}
				if(tag==0) System.out.println(line+" is not cyclic");
				else System.out.println(line+" is cyclic");
			}
			else
				 System.out.println(line+" is cyclic");
		}		
	}
	
	public static boolean judge(String a,String b)
	{
		int length=b.length();
		if(a.length()==length)
		{
			String sub;
			int i;
			for(i=0;i<length;i++)
			{
				sub=b.substring(i);
				if(a.startsWith(sub)) break;
			}
			if(i==length) 
				return false;
			else
			{
				String asub=a.substring((length-i));
				String bsub=b.substring(0, i);
				if(asub.equals(bsub)) return true;
				else return false;
			}			
		}
		else 
			return false;
	}
}

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