HDU-1002,A + B Problem II(Java大数)

简介: HDU-1002,A + B Problem II(Java大数)

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


AC Code:  


import java.util.*;
import java.math.*;
public class Main
{
  public static void main(String[] args)
  {
    Scanner input=new Scanner(System.in);
    int t=input.nextInt();
    int ans=1;
    for(int i=1;i<=t;i++)
    {
      BigDecimal a=input.nextBigDecimal();
      BigDecimal b=input.nextBigDecimal();
      System.out.println("Case "+ans+":");
      System.out.println(a+" + "+b+" = "+a.add(b));
      ans++;
      if(ans<=t)
        System.out.println();
    }
    input.close();
  }
}


相关文章
|
1月前
|
Java 编译器
有关电脑中idea编译报错问题java: No implementation was created for AdminUserConverter due to having a problem in
有关电脑中idea编译报错问题java: No implementation was created for AdminUserConverter due to having a problem in
34 0
java.lang.Error: Unresolved compilation problem: The type List is not generic; it cannot be parame
java.lang.Error: Unresolved compilation problem: The type List is not generic; it cannot be parame
|
6月前
|
Cloud Native Java Go
解决 Spring Boot 和 Gradle Java 版本兼容性问题:A problem occurred configuring root project ‘demo1‘. > Could n
解决 Spring Boot 和 Gradle Java 版本兼容性问题:A problem occurred configuring root project ‘demo1‘. > Could n
409 0
|
8月前
|
Java
Java 中大数的处理方案BigInteger和BigDecimal类的使用
Java 中大数的处理方案BigInteger和BigDecimal类的使用
53 0
|
Java 索引
java中大数的计算BigInteger和BigDecimal两个类的常用方法
java中大数的计算BigInteger和BigDecimal两个类的常用方法
70 0
|
Java 编译器
有关电脑中idea编译报错问题java: No implementation was created for AdminUserConverter due to having a problem in
有关电脑中idea编译报错问题java: No implementation was created for AdminUserConverter due to having a problem in
1201 0
有关电脑中idea编译报错问题java: No implementation was created for AdminUserConverter due to having a problem in
|
Java
poj3320Jessica's Reading Problem—尺取法(java)
这个和裸的尺取优点不同的是,他需要一个map来维护判断而不是sum维护判断。在右侧从左向右遍历的同时,用一个map<Integer,Integer>来维护元素,map.keyset()就可以判断是否包含所有元素,数值用来判断改元素出现次数是否应移除改元素—左侧标记右移的时候判断。
61 0
|
Java Python
Java大数BigInteger-用法记录
Java大数BigInteger-用法记录 提交代码 使用方式 构造一个对象 加 add 减 subtract 乘 multiply 除 divide gcd 最大公约数 lcm 最小公倍数 mod % pow ^次方 abs 绝对值 开方sqrt modPow 次方取余 equals判断是否相等 compareTo 比较大小 常用的就上面这些啦
350 0
Java大数BigInteger-用法记录
|
Java 应用服务中间件 编译器
Java: Unresolved compilation problem的解决方法
Java: Unresolved compilation problem的解决方法
Java: Unresolved compilation problem的解决方法
|
Java
java核心技术卷I中的细节(2- 大数)
java核心技术卷I中的细节(2- 大数)
92 0
java核心技术卷I中的细节(2- 大数)