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");
            }
        }   
    }
}

猜你喜欢

转载自www.cnblogs.com/zxz666/p/9639906.html
今日推荐