上机题目(初级)-大数求和

来源:互联网 发布:什么是多路访问网络 编辑:程序博客网 时间:2024/05/07 18:26

描述: 

给定两个非常大的正整数A和B,位数在50至100之间。求C=A+B;

 题目类别: 字符串 难度: 中级 运行时间限制:10Sec内存限制:128MByte阶段: 入职前练习 输入: 

因为A和B很大,从高位到低位,以字符串的形式输入两行数字A和B。A和B的位数在50至100之间。

 输出: 

以字符串形式,输出一行,表示A和B的和。

 样例输入:
1111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222                   
样例输出:
3333333333333333333333333333333333333333333333333


代码如下:

import java.io.*;import java.util.*;public class Main {public static void main(String[] args) {Scanner cin = new Scanner(new BufferedInputStream(System.in));String add1 = cin.nextLine();String add2 = cin.nextLine();java.math.BigInteger res1 = new java.math.BigInteger(add1);java.math.BigInteger res2 = new java.math.BigInteger(add2);java.math.BigInteger result = res1.add(res2);System.out.println(result);}}

**喜欢的朋友请关注我,另欢迎阅读我的电子书 
百度阅读: 
http://yuedu.baidu.com/ebook/284b41a1e518964bce847c90?pn=1&click_type=10010002&rf=http%3A%2F%2Fblog.csdn.net%2Fyayun0516%2Farticle%2Fdetails%2F51277821 
亚马逊: 
http://www.amazon.cn/Android-%E7%99%BE%E6%88%98%E7%BB%8F%E5%85%B8-%E5%8D%B7I-%E5%BC%A0%E4%BA%9A%E8%BF%90/dp/B01ER5R9U2?ie=UTF8&keywords=Android%E7%BB%8F%E5%85%B8&qid=1461806976&ref_=sr_1_6&s=digital-text&sr=1-6**



1 0
原创粉丝点击