题目1198:a+b
题目描述:
实现一个加法器,使其能够输出a+b的值。
输入:
输入包括两个数a和b,其中a和b的位数不超过1000位。
输出:
可能有多组测试数据,对于每组数据,
输出a+b的值。
样例输入:
2 6
10000000000000000000 10000000000000000000000000000000
样例输出:
8
10000000000010000000000000000000
ps:
(1)、如果要将一个大数以n进制形式读入,可用 cin.nextBigInteger(n);
(2)、如果要将一个大数转换成其它进制的字符串,可用num.toString(n);其中num是要转换的大数,n是要转换的进制。
(3)、其它类型数据转换为大数: BigInteger b = BigInteger.valueOf ( Type t );
(4)、大数转换为其它类型数据,如转换为int数据,则 int x =b.intValue();其中b为BigInteger类型数据。
84984KB
355B
980MS
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
while (cin.hasNextBigInteger()) {
BigInteger a = cin.nextBigInteger();
BigInteger b = cin.nextBigInteger();
System.out.println(a.add(b));
}
}
}