HDU 1002 A + B Problem II -- java大法好
2016-05-02 22:26
375 查看
A + B Problem II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 306140 Accepted Submission(s): 59153
Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using
32-bit integer. You may assume the length of each integer will not exceed 1000.
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line
between two test cases.
Sample Input
2 1 2 112233445566778899 998877665544332211
Sample Output
Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { BigInteger a,b; int t; Scanner cin = new Scanner(System.in); t = cin.nextInt(); for(int i=1;i<=t;i++){ System.out.println("Case"+" "+i+":"); a = cin.nextBigInteger(); b = cin.nextBigInteger(); if(i<t){ System.out.println(a+" + "+b+" = "+a.add(b)); System.out.println(); } else{ System.out.println(a+" + "+b+" = "+a.add(b)); } } } }
相关文章推荐
- Java中List和ArrayList的区别(加入了个人见解)
- 我爱学Java之Thread中stop(),suspend(),resume()为什么不安全
- 第59课:使用Java实战RDD和DataFrame转换操作
- jdbc的使用
- java--IO 2
- Java笔记---Hadoop 2.7.1下WordCount程序详解
- springMVC(10)------springMVC重定向
- 第58课:使用Java和Scala在IDE中开发DataFrame实战
- Java线程泄露的分析与处理
- Java8新特性Stream API与Lambda表达式详解(1)
- 高吞吐量的分布式发布订阅消息系统Kafka--spring-integration-kafka的应用
- java中对类的方法的进行加强(1)--对类方法的覆盖
- 20145110 《Java程序设计》第四次实验报告
- Java中获取路径的方法_自我分析
- 水仙花数-java实现
- java中的IO整理
- Java中多态的实现机制
- Java中获取路径的方法_自我分析
- Java中Exception的种类
- Java网页爬虫获取邮件地址