Java BigInteger类知识点总结


(1)程序有时需要处理大整数,java.math包中的BigInteger类提供任意精度的整数运算,可以使用构造方法:

public BigInteger(String VAL)构造一个十进制的BigInteger对象,该构造方法可以发生NumberFormatException异常,也就是说,字符串参数VAL中如果含有非数字字符就会发生NumberFormatException异常。

(2)BigInteger类的常用方法:

public BigInteger add(BigInteger val)   返回当前大整数对象与参数指定的大整数对象的和

public BigInteger subtract(BigInteger val)  返回当前大整数对象与参数指定的大整数对象的差

public BigInteger multiply(BigInteger val)   返回当前大整数对象与参数指定的大整数对象的积

public BigInteger devide(BigInteger val)    返回当前大整数对象与参数指定的大整数对象的商

public BigInteger remainder(BigInteger val)    返回当前大整数对象与参数指定的大整数对象的余

public int compareTo(BigInteger val)    返回当前大整数对象与参数指定的大整数对象的比较结果,返回值是1、-1、0,分别表示当前大整数对象大于、小于或等于参数指定的大整数。

public BigInteger abs()    返回当前大整数对象的绝对值

public BigInteger pow(int exponent)   返回当前大整数对象的exponent次幂。

public String toString()    返回当前当前大整数对象十进制的字符串表示。

public String toString(int p)   返回当前大整数对象p进制的字符串表示。

(3)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM