【JAVA大数训练】A + B Problem II

简介:

A + B Problem II
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 196702    Accepted Submission(s): 37626


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) {
  Scanner input=new Scanner(System.in);
  int n=input.nextInt();
  int k=1;
  while(n!=0)
  {
   BigInteger a=input.nextBigInteger();
   BigInteger b=input.nextBigInteger();
      BigInteger c=a.add(b);
                    n--;
      if(k!=1)
       System.out.println();//输出换行
            System.out.println("Case "+k+":");
            k++;
      System.out.println(a+" + "+b+" = "+c);
  }
 }
}
相关文章
|
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
1634 0
|
数据采集 机器学习/深度学习 Java
Java 大视界 -- Java 大数据在智能体育赛事运动员体能监测与训练计划调整中的应用(200)
本篇文章聚焦 Java 大数据在智能体育赛事中对运动员体能监测与训练计划的智能化应用。通过构建实时数据采集与分析系统,结合机器学习模型,实现对运动员体能状态的精准评估与训练方案的动态优化,推动体育训练迈向科学化、个性化新高度。
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
|
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
2131 0
|
Java
Java 中大数的处理方案BigInteger和BigDecimal类的使用
Java 中大数的处理方案BigInteger和BigDecimal类的使用
604 0
|
机器学习/深度学习 分布式计算 算法
Java中的机器学习模型集成与训练实践
Java中的机器学习模型集成与训练实践
|
机器学习/深度学习 人工智能 分布式计算
Java中的机器学习模型集成与训练
Java中的机器学习模型集成与训练
|
机器学习/深度学习 算法 Java
Java中的机器学习模型集成与训练策略
Java中的机器学习模型集成与训练策略
|
JavaScript Java 测试技术
基于Java的智能训练管理平台的设计与实现(源码+lw+部署文档+讲解等)
基于Java的智能训练管理平台的设计与实现(源码+lw+部署文档+讲解等)
177 0
|
安全 Java API
Java的第十篇文章——常用类下(String、大数类、日期类和包装类)
Java的第十篇文章——常用类下(String、大数类、日期类和包装类)