Java-POJ1001- seeking precision exponentiation

 Reference blog: https://www.cnblogs.com/downrainsun/p/11041960.html

 

 

. 1  Package poj.ProblemSet;
 2  
3  Import java.math.BigDecimal;
 . 4  Import java.util.Scanner;
 . 5  / * 
. 6      .4321 ^ 20 is represented by results in scientific notation
 7      0.100 ^ 3 = 0.0001000000
 8      scientific notation in turn java conventional digital representation
 . 9      stripTrailingZeros () remove the end 0
 10      toPlainString () turned generally counting output
 . 11  * / 
12 is  
13 is  public  class poj1001 {
 14      public  static  void main (String [] args) {
 15  
16          Scanner CIN = new new Scanner(System.in);
17         while(cin.hasNext()) {
18             BigDecimal a=new BigDecimal(cin.next());
19             BigDecimal ans=a.pow(cin.nextInt());
20             String s=ans.stripTrailingZeros().toPlainString();
21             if(s.startsWith("0"))s=s.substring(1);//去掉0.01的首零->.01
22             System.out.println(s);
23         }
24     }
25 }

 

Guess you like

Origin www.cnblogs.com/JasonCow/p/12232101.html