zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    i++与++i
    acm语录
    c# SQL2000 access 远程连接操作
    C# 四舍五入函数
    WINDOWS 2003 远程桌面记录登陆IP
    jquery 资源
    php google baidu 分页
    Solutions to place plus or minus signs to a nonzero digits sequence 123456789 so that result of thus described arithmetic opera
    VB获取网页下文字的链接地址
    php cache 缓存方法类一
  • 原文地址:https://www.cnblogs.com/S-Mustard/p/7605761.html
Copyright © 2011-2022 走看看