多语言展示
当前在线:1139今日阅读:84今日分享:32

java基础9.4.1 大数字计算之BigInteger

在java中提供BigInteger用于解决大整数的处理类。由于int和Integer等都是有精度的,如果超出范围就会造成计算失误。而BigInteger就是解决方法。
工具/原料
1

电脑

2

java

方法/步骤
1

BigInteger的构造方法最常用的就是字符串数字构造

2

还可以使用BigInteger.valueOf(111);方法返回BigInteger对象

3

我们来使用一些基本的运算方法。做加法运算:BigInteger add = b1.add(b2);

4

做减法运算:BigInteger subtract = b1.subtract(b2);

5

做乘法运算:BigInteger multiply = b1.multiply(b2);

注意事项

使用字符串进行构造是最常用的。

推荐信息