java实现大数相加问题

闲来没事。写了个acm中常常遇到的大数加减问题的java 解决代码,我想说。用java的BigInteger 非常easy。

大爱java!!

比如:

实现多组输入大数加减问题:

import java.math.*;
import java.util.*;

public class Bignum {
  public static void main(String[] args) {
     BigInteger bigNumOne;
     BigInteger bigNumTwo;

     Scanner in = new Scanner(System.in);

     while(in.hasNextBigInteger()) {
       bigNumOne  = in.nextBigInteger();
       bigNumTwo  = in.nextBigInteger();

       bigNumOne =  bigNumOne.add(bigNumTwo);

       System.out.println(bigNumOne);
     }
  }
}



有没有一种非常爽的感觉!

原文地址:https://www.cnblogs.com/bhlsheji/p/5064768.html