BigInteger类

1.java处理大数的方法(注意它处理的仅仅是整数,正负都可以)

将不可完成的数值放入字符串里面,再做操作。

2.java.math.BigInteger(加减乘除的大数运算)

3.将需要计算的大数值转成字符串,然后用BigInteger接收,帮助我们计算(这个计算一般无法用正常的数据类型来完成)

4.加法

BigInteger a=new BigInteger("10000000000000000000000000000000000000000000");
    BigInteger b=new BigInteger("10000000000000000000000000000000000000000000");
    System.out.println(a.add(b));
//20000000000000000000000000000000000000000000

5.减法

BigInteger a=new BigInteger("10000000000000000000000000000000000000000000");
    BigInteger b=new BigInteger("10000000000000000000000000000000000000000000");
    System.out.println(a.subtract(b));
//0

6.乘

BigInteger a=new BigInteger("10000000000000000000000000000000000000000000");
    BigInteger b=new BigInteger("10000000000000000000000000000000000000000000");
    System.out.println(a.multiply(b));

//100000000000000000000000000000000000000000000000000000000000000000000000000000000000000

 

7.除

BigInteger a=new BigInteger("10000000000000000000000000000000000000000000");
    BigInteger b=new BigInteger("10000000000000000000000000000000000000000000");
    System.out.println(a.divide(b));
//1

8.取商取余

    BigInteger a=new BigInteger("20");
    BigInteger b=new BigInteger("3");
    System.out.println(a.divideAndRemainder(b));
    BigInteger [] c=a.divideAndRemainder(b);
    for(int i=0;i<2;i++)
        System.out.println(c[i]);
    }

//[Ljava.math.BigInteger;@15db9742
//6
//2

 

posted @ 2017-09-28 11:11  S-Mustard  阅读(263)  评论(0编辑  收藏  举报