java大数据类型BigInteger用法

BigInteger

public class test {
    public static void main(String[] args) {
        BigInteger n=new BigInteger("123");
        BigInteger tmp=new BigInteger("2");
        n=n.add(BigInteger.valueOf(12));
        n=n.subtract(tmp);
        n=n.multiply(tmp);
        n=n.divide(tmp);
        System.out.println(n.longValue());
    }
}
  • java.math类,继承自Number
  • 加减乘除都需要使用类方法,只能和BigInteger类型的变量操作
  • 如果转化为long超过long最大值会显示Infinity

你可能感兴趣的:(Java)