A+B for Input-Output Practice (V)
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
Your task is to calculate the sum of some integers.
Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.
Output
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.
Sample Input
2 4 1 2 3 4 5 1 2 3 4 5
Sample Output
10 15
Hint
Source
HDOJ
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int t=in.nextInt();
for(int j=0;j<t;j++)
{
int n=in.nextInt();
int sum=0;
for(int i=0;i<n;i++)
{
int x=in.nextInt();
sum+=x;
}
System.out.println(sum);
}
}
}
本文详细解析了一个经典的A+B输入输出练习题,题目要求计算一组整数的总和。输入包含一个整数N,随后是N组数据,每组数据开始是一个整数M,接着是M个整数。对于每组输入整数,输出它们的和。通过示例展示了如何使用Java编程语言解决该问题。

被折叠的 条评论
为什么被折叠?



