zoukankan      html  css  js  c++  java
  • java大数相加

    import java.math.BigInteger;

    import java.util.Scanner;

     public class Bignum{    public static void main(String[] args) {
            Scanner s=new Scanner(System.in);
            BigInteger a=new BigInteger("0");
            BigInteger b=new BigInteger("0");
            while(s.hasNext()){
                a=s.nextBigInteger();
                /*
                 * 不是0的时候就进行相加,若为0则表示输入结束,需要进行输出。
                 */
                if(!(a.toString()==("0")))
                    b=b.add(a);                  
                if(a.toString()==("0")){
                    System.out.println(b);
                    b=new BigInteger("0");
                }
            }   
        }
    }

    add() 加法
    subtract() 减法
    multiply() 乘法
    divide() 除法

    BigInteger abs()  返回大整数的绝对值
    stripTraillingZeros():把不影响数值大小的0全去掉
    Boolean isProbablePrime(BigInteger n)  判断大数是否为素数
    nextProbablePrime(BigInteger n)   返回比大数n大的为素数的数 BigInteger add(BigInteger val) 返回两个大整数的和 BigInteger and(BigInteger val) 返回两个大整数的按位与的结果 BigInteger andNot(BigInteger val) 返回两个大整数与非的结果 BigInteger divide(BigInteger val) 返回两个大整数的商 double doubleValue() 返回大整数的double类型的值 float floatValue() 返回大整数的float类型的值 BigInteger gcd(BigInteger val) 返回大整数的最大公约数 int intValue() 返回大整数的整型值 long longValue() 返回大整数的long型值 BigInteger max(BigInteger val) 返回两个大整数的最大者 BigInteger min(BigInteger val) 返回两个大整数的最小者 BigInteger mod(BigInteger val) 用当前大整数对val求模 BigInteger multiply(BigInteger val) 返回两个大整数的积 BigInteger negate() 返回当前大整数的相反数 BigInteger not() 返回当前大整数的非 BigInteger or(BigInteger val) 返回两个大整数的按位或 BigInteger pow(int exponent) 返回当前大整数的exponent次方 BigInteger remainder(BigInteger val) 返回当前大整数除以val的余数 BigInteger leftShift(int n) 将当前大整数左移n位后返回 BigInteger rightShift(int n) 将当前大整数右移n位后返回 BigInteger subtract(BigInteger val)返回两个大整数相减的结果 byte[] toByteArray(BigInteger val)将大整数转换成二进制反码保存在byte数组中 String toString() 将当前大整数转换成十进制的字符串形式 BigInteger xor(BigInteger val) 返回两个大整数的异或
    BigInteger a.toString(b)将10进制的a变成b进制的数
  • 相关阅读:
    对人脑学习的一些领悟
    象形法,快速记忆魔方公式
    公司招聘
    微信游戏《全民炫舞》开发公司h3d2 engine和QQ炫舞2 布料系统技术介绍
    四维几何世界中的盒子
    HI-LO计数法,赌桌,与机会
    离开天朝,跑到新加坡了
    精选19款华丽的HTML5动画和实用案例
    精选29款非常实用的jQuery应用插件
    【特别推荐】8个富有创意的jQuery/CSS3插件
  • 原文地址:https://www.cnblogs.com/zxz666/p/9639906.html
Copyright © 2011-2022 走看看