20170504@BigInterger类

来源:互联网 发布:水性科天板材 知乎 编辑:程序博客网 时间:2024/04/28 18:17

java中long型为最大整数类型,但对于超过long型的数据,在Java超过long型的整数已经不能被称为整数了,它们被封装成BigInteger对象。

推荐使用的构造方法:

BigInteger(String val) 

将 BigInteger 的十进制字符串表示形式转换为 BigInteger。

四则运算:
在BigInteger类中,实现四则运算是使用方法来实现,并不是采用运算符。所得到的结果,也并不是一个整数,而是一个BigInterger类型的对象

1.加

BigInteger add(BigInteger val) 

返回其值为 (this + val) 的 BigInteger。

2.减

 BigInteger subtract(BigInteger val) 

返回其值为 (this - val) 的 BigInteger。

3.乘

 BigInteger multiply(BigInteger val) 

返回其值为 (this * val) 的 BigInteger。

4.除

BigInteger divide(BigInteger val) 

返回其值为 (this / val) 的 BigInteger。

0 0