BigInteger类(大整数)
一.为什么要用BigInteger?
-
Integer只能操作指定范围内的整形数据,超过范围将无法操作
-
这是就需要引入BigInteger类来进行大整数操作
-
这些大整数以字符串的形式输入
-
位于java.math包中
二.BigInteger类的常用方法
//创建对象的方法
BigInteger b1 = new BigInteger("11111111111111111111");
BigInteger b2 = new BigInteger("22222222222222222222");
//常用方法
System.out.println(b1.add(b2)); //加法操作
System.out.println(b1.subtract(b2)); //减法操作
System.out.println(b1.multiply(b2)); //乘法操作
System.out.println(b1.divide(b2)); //除法操作
System.out.println(b1.max(b2)); //较大数
System.out.println(b1.min(b2)); //较小数