BigInteger
1.BigInteger介绍
1.问题描述:我们操作数据,将来的数据有可能非常大,大到比long还要大,这种数据我们一般称之为"对象"
2.作用:
处理超大整数
3.构造:
BigInteger(String val) -> 参数的格式必须是数字形式
4.方法:
BigInteger add(BigInteger val) 返回其值为 (this + val) 的 BigInteger
BigInteger subtract(BigInteger val) 返回其值为 (this - val) 的 BigInteger
BigInteger multiply(BigInteger val) 返回其值为 (this * val) 的 BigInteger
BigInteger divide(BigInteger val) 返回其值为 (this / val) 的 BigInteger
2.BigInteger使用
public class Demo02BigInteger {
public static void main(String[] args) {
BigInteger b1 = new BigInteger("121212121212121212121212121212121212121");
BigInteger b2 = new BigInteger("121212121212121212121212121212121212121");
//BigInteger add(BigInteger val) 返回其值为 (this + val) 的 BigInteger
System.out.println(b1.add(b2));
//BigInteger subtract(BigInteger val) 返回其值为 (this - val) 的 BigInteger
System.out.println(b1.subtract(b2));
//BigInteger multiply(BigInteger val) 返回其值为 (this * val) 的 BigInteger
System.out.println(b1.multiply(b2));
//BigInteger divide(BigInteger val) 返回其值为 (this / val) 的 BigInteger
System.out.println(b1.divide(b2));
}
}
int intValue() 将BigInteger转成int
long longValue() 将BigInteger 转成 long
BigInteger上限:42亿的21亿次方,内存根本扛不住,所以我们可以认为BigInteger无上限