BigInteger类
1.创建对象:
-
短整型范围:-32768
32767,长整型范围:-21474836482147483647 -
BigInteger(String value):将value字符串变成BigInteger类型数据
BigInteger b_int1=new BigInteger("50");
2.常用运算方法:
2.加法运算:
-
BigInteger add(BigInteger val):求两个BigInteger类型数据的和,如:高精度加法
BigInteger b_int1=new BigInteger("50"); BigInteger b_int2=new BigInteger("5"); BigInteger a_int = b_int1.add(b_int2); System.out.println(a_int); //输出:55
3.减法运算:
-
BigInteger subtract(BigInteger value):求两个BigInteger类型数据的差
BigInteger b_int1=new BigInteger("50"); BigInteger b_int2=new BigInteger("5"); BigInteger a_int = b_int1.subtract(b_int2); System.out.println(a_int); //输出:45
4.乘法运算:
-
BigInteger multiply(BigInteger value):求两个BigInteger类型数据的积
BigInteger b_int1=new BigInteger("50"); BigInteger b_int2=new BigInteger("5"); BigInteger a_int = b_int1.multiply(b_int2); System.out.println(a_int); //输出:250
5.除法运算:
-
BigInteger divide(BigInteger divisor):求两个BigInteger类型数据的商
BigInteger b_int1=new BigInteger("50"); BigInteger b_int2=new BigInteger("5"); BigInteger a_int = b_int1.divide(b_int2); System.out.println(a_int); //输出:10
6.求余数运算:
-
BigInteger remainder(BigInteger divisor):求余数,求BigInteger类型数据除以divisor的余数
BigInteger b_int1=new BigInteger("50"); BigInteger b_int2=new BigInteger("5"); BigInteger a_int = b_int1.remainder(b_int2); System.out.println(a_int); //输出:0
7.求模运算:
-
BigInteger modInverse(BigInteger m):求模,求BigInteger类型数据对m求模
3.其他方法:
-
BigInteger max(BigInteger value):最大数,求两个BigInteger类型数据的最大值
-
BigInteger min(BigInteger value):最小数,求两个BigInteger类型数据的最小值。
-
BigInteger gcd(BigInteger value):最大公约数,求两个BigInteger类型数据的最大公约数
-
BigInteger abs():绝对值,求BigInteger类型数据的绝对值
-
BigInteger negate():相反数,求BigInteger类型数据的相反数