本博主将用CSDN记录软件开发求学之路上亲身所得与所学的心得与知识,有兴趣的小伙伴可以关注博主!
也许一个人独行,可以走的很快,但是一群人结伴而行,才能走的更远!让我们在成长的道路上互相学习,欢迎关注!
⭕
Integer类作为int的包装类,能存储的最大整型值为231-1,Long类也是有限的,最大为263-1。如果要表示再大的整数,不管是基本数据类型还是他们的包装类都无能为力,更不用说进行运算了。
⭕
java.math包的BigInteger可以表示不可变的任意精度的整数。BigInteger提供所有Java的基本整数操作符的对应物,并提供java.lang.Math的所有相关方法。另外,BigInteger还提供以下运算:模算术、GCD计算、质数测试、素数生成、位操作以及一些其它操作。
| 序号 | 构造器 | 作用 |
|---|---|---|
| 1 | BigInteger(String val) | 根据字符串构建BigInteger对象 |
| 序号 | 方法 | 作用 |
|---|---|---|
| 1 | public BigInteger abs() | 返回此 BigInteger 的绝对值的 BigInteger |
| 2 | BigInteger add(BigInteger val) | 返回其值为 (this + val) 的 BigInteger |
| 3 | BigInteger subtract(BigInteger val) | 返回其值为 (this - val) 的 BigInteger |
| 4 | BigInteger multiply(BigInteger val) | 返回其值为 (this * val) 的 BigInteger |
| 5 | BigInteger divide(BigInteger val) | 返回其值为 (this / val) 的BigInteger,整数相除只保留整数部分。 |
| 6 | BigInteger remainder(BigInteger val) | 返回其值为 (this % val) 的 BigInteger |
| 7 | BigInteger[] divideAndRemainder(BigInteger val) | 返回包含 (this / val) 后跟(this % val) 的两个 BigInteger 的数组 |
| 9 | BigInteger pow(int exponent) | 返回其值为(thisexponent) 的 BigInteger |