• 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
  • 相关阅读:
    python基础知识第三篇(列表)
    python基础知识第二篇(字符串)
    python基础知识第一篇(认识Python)
    tomacat环境搭建
    Python的内存管理机制
    selenium定位方法
    python+selenium xpath定位
    django--创建及配置项目app
    django--cookies和session
    django--orm--012
  • 原文地址:https://www.cnblogs.com/S-Mustard/p/7605761.html
Copyright © 2020-2023  润新知