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 kaka1988 at 2010-07-10 03:15:54 on Problem 1001
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {
	
	public static void main(String[] args) {
		BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
		String inputStr = "";
		try {
			while((inputStr = cin.readLine()).length() > 0) {
				System.out.println();
				BigDecimal r = new BigDecimal(inputStr.substring(0, 6).trim());
				int n = Integer.parseInt(inputStr.substring(7).trim());
				if(r.compareTo(new BigDecimal("0")) == 0) {
					System.out.print(0);
					continue;
				}
				String str = r.pow(n).toPlainString();
				if(str.charAt(0) == '0' && str.indexOf('.') >= 0) {
					str = str.substring(1);
				}
				while(str.charAt(str.length() - 1) == '0') {
					str = str.substring(0, str.length() - 2);
				}
				System.out.print(str);
			}
		} catch (NumberFormatException e1) {
			e1.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try {
			cin.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}

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