天天看点

BigInteger类

程序有时会处理大整数,其取值超出了基本整数类型的范畴可以使用java.math包中的BigInteger类来处理,该类可以提供任意精度的整数运算

BigInteger类的构造方法

public BigInteger(String s)

如果s中包含非法字符,会发生NumberFormatException异常

public BigInteger add(BigInteger n)

返回当前对象与n之和

public BigInteger subtract(BigInteger n)

返回当前对象与n之差

public BigInteger multiply(BigInteger n)

返回当前对象与n之积

public BigInteger divide(BigInteger n)

返回当前对象与n之商

public BigInteger remainder(BigInteger n)

返回当前对象与n的余数

public BigInteger abs()

返回当前对象的绝对值

public BigInteger pow(int m)

返回当前对象的m次幂

BigInteger类常用方法

public int compareTo(BigInteger n)

返回当前对象与n的比较结果,当前对象大于n时,返回1;小于n时,返回-1;相等时,返回0

public String toString()

返回当前对象的字符串表示

public String toString(int m)

返回当前对象的m进制字符串表示

继续阅读