BigInteger : 能够存取比Long更大的整数,可以任意大小
构造方法 : BigInteger(String val) : 将 BigInteger 的十进制字符串表示形式转换为 BigInteger。
数学运算的方法:
BigInteger add(BigInteger bi) : 加法运算
BigInteger subtract(BigInteger val) : 减法运算
BigInteger multiply(BigInteger val) : 乘法运算
BigInteger divide(BigInteger val) : 除法运算
ex:
public class Demo {
public static void main(String[] args) {
BigInteger bi1 = new BigInteger("2");
BigInteger bi2 = new BigInteger("3");
System.out.println(bi1.add(bi2));//2+3=5
System.out.println(bi1.subtract(bi2));//2-3=-1
System.out.println(bi1.multiply(bi2));//2*3=6
System.out.println(bi1.divide(bi2));//2/3=0
}
}
运行结果图:

最后
以上就是俊秀电源最近收集整理的关于JavaSE基础(79) BigInteger(能够存取比Long更大的整数,可以任意大小)的全部内容,更多相关JavaSE基础(79)内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复