1004: A+B(基本输入输出4)
时间限制: 1 Sec 内存限制: 128 MB提交: 744 解决: 466
[ 提交][ 状态][ 讨论版]
题目描述
多个数求和。
输入
输入包含多个测试用例。每个测试用例包含一个正整数N,随后是N个整数跟在同一行上。当某个测试用例以0开始,终止输入,且该用例不处理。
输出
对于每一组测试用例,输出齐对应的和,每组数据一行。
样例输入
3 1 2 4
1 23
5 1 3 5 7 9
0
样例输出
7
23
25
CODE:
import java.util.*; public class Main{ public static void main(String[] args){ Scanner in=new Scanner(System.in); while(in.hasNext()){ int n=in.nextInt(); if(n==0) break; else{ int sum=0; for(int i=1;i<=n;i++){ int a=in.nextInt(); sum+=a; } System.out.println(sum); } } } }