Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:求助!Java写的,总是Runtime ErrorIn Reply To:求助!Java写的,总是Runtime Error Posted by:kaka1988 at 2010-07-10 03:15:54 > 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator