HDU-1002-(A + B Problem II)
解题思路
1.分析题意,输入可能为超出int范围,所以使用BigInteger
2.题目要求每个case,输出空白行
解题遇到的问题
Output a blank line between two test cases.
题目中声明了,每两个case之间有空白行,最后一个case不需要空白行
后续需要总结学习的知识点
无
##解法1
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner mScanner = new Scanner(System.in);
int t = mScanner.nextInt();
int i = 1;
while (i <= t) {
BigInteger a = mScanner.nextBigInteger();
BigInteger b = mScanner.nextBigInteger();
System.out.println("Case " + i + ":");
System.out.println(a + " + " + b + " = " + a.add(b).toString());
if (i != t) {
System.out.println();
}
i++;
}
mScanner.close();
}
}
网友评论