当前位置: 代码迷 >> 综合 >> JavaSE基础(79) BigInteger(能够存取比Long更大的整数,可以任意大小)
  详细解决方案

JavaSE基础(79) BigInteger(能够存取比Long更大的整数,可以任意大小)

热度:76   发布时间:2023-12-13 15:17:26.0

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=5System.out.println(bi1.subtract(bi2));//2-3=-1System.out.println(bi1.multiply(bi2));//2*3=6System.out.println(bi1.divide(bi2));//2/3=0   }
}

运行结果图:

  相关解决方案