题目大意:输入一个整数作为测试用例数。接着输入若干个加数(被加数),以0作为结束符.输出若干个加数相加后的结果
解题思路:看着题目直接写就行
代码如下:
package com.njupt.bigInteger;
import java.math.BigInteger;
import java.util.Scanner;
public class HDU_1047_1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
BigInteger a,b;
BigInteger zero = new BigInteger("0");
while(scanner.hasNextInt()){
int t = scanner.nextInt();
for(int i = 1 ; i <= t ; ++i){
boolean flag = true;
b = zero;
while(flag){
a = scanner.nextBigInteger();
if(a.compareTo(zero) == 0){
flag = false;
}
b = b.add(a);
}
System.out.println(b);
/**
* 实现每个测试用例之间都有一个空行
*/
if(i<t){
System.out.println();
}
}
}
}
}