当前位置:   article > 正文

Java-BigInteger类(详解)

biginteger



前言

本博主将用CSDN记录软件开发求学之路上亲身所得与所学的心得与知识,有兴趣的小伙伴可以关注博主!
也许一个人独行,可以走的很快,但是一群人结伴而行,才能走的更远!让我们在成长的道路上互相学习,欢迎关注!

一、概述

Integer类作为int包装类,能存储的最大整型值为231-1Long类也是有限的,最大为263-1。如果要表示再大的整数,不管是基本数据类型还是他们的包装类都无能为力,更不用说进行运算了。

java.math包的BigInteger可以表示不可变的任意精度的整数。BigInteger 提供所有 Java的基本整数操作符的对应物,并提供 java.lang.Math 的所有相关方法。另外,BigInteger 还提供以下运算:模算术、GCD计算、质数测试、素数生成、位操作以及一些其它操作。

二、构造器

序号构造器作用
1BigInteger(String val)根据字符串构建BigInteger对象

三、常用方法

序号方法作用
1public BigInteger abs()返回此 BigInteger 的绝对值的 BigInteger
2BigInteger add(BigInteger val)返回其值为 (this + val)BigInteger
3BigInteger subtract(BigInteger val)返回其值为 (this - val)BigInteger
4BigInteger multiply(BigInteger val)返回其值为 (this * val)BigInteger
5BigInteger divide(BigInteger val)返回其值为 (this / val)BigInteger,整数相除只保留整数部分。
6BigInteger remainder(BigInteger val)返回其值为 (this % val)BigInteger
7BigInteger[] divideAndRemainder(BigInteger val)返回包含 (this / val) 后跟(this % val) 的两个 BigInteger 的数组
9BigInteger pow(int exponent)返回其值为(thisexponent)BigInteger
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/321935
推荐阅读
相关标签
  

闽ICP备14008679号