BigDecimal in java
Java. math. BigDecimal
The data range that other common types cannot represent, such as double, cannot exceed 16 bits, but this class can. Today, I wrote the 1001 question of ACM at Peking University. I wrote it in C ++ and then in java. I think java is simple, but I am not familiar with java. Learn java from now on.
This question uses BigDecimal in java.
You cannot perform operations on the objects of common ++. Instead, use the method in its class.
BigDecimal add (BigDecimal augend): Addition
BigDecimal subtract (BigDecimal subtrahend): subtraction
BigDecimal divide (BigDecimal divisor): Division
BigDecimal pow (int n): Power
BigDecimal multiply (BigDecimal multiplicand): Multiplication
The resulting decimal number must be zero after the decimal point. BigDecimal stripTrailingZeros () is used to return the BigDecimal number, but all BigDecimal values with Zero tail are removed from this representation.
Use the String toPlainString () to return the String representation of the BigDecimal without an exponential field. In general, it is a direct display, which is not represented by scientific notation.
Finally, paste the question code (java) of ACM1001 in the back and remember it later.
import java.io.*; import java.util.*; import java.math.BigDecimal; public class Main { public static void main(String args[])throws Exception { Scanner cin=new Scanner(System.in); while(cin.hasNext()) { BigDecimal r=cin.nextBigDecimal(); int n=cin.nextInt(); r=r.pow(n).stripTrailingZeros(); String m_string=r.toPlainString(); if(m_string.charAt(0)=='0') m_string=m_string.substring(1); System.out.println(m_string); } } }