java的加法运算_Java实现大数加法运算

题目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));

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值