java实现大数相加问题

来源:互联网 发布:js dom方法 编辑:程序博客网 时间:2024/05/18 03:08

闲来没事,写了个acm中经常遇到的大数加减问题的java 解决代码,我想说,用java的BigInteger 很容易。大爱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);     }  }}



有没有一种很爽的感觉!

4 0