ACM Steps ---- Section1

来源:互联网 发布:linux查看svn账号密码 编辑:程序博客网 时间:2024/05/14 10:31

这里挑选的是两个水题,输入和输出的练习


Sample Input
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3
Sample Output
10

15

6


这道题的陷阱在于 输出结果 之间存在 一个空格  最后一个结果之后没有空格;

import java.util.Scanner;
public class PracticeVIII {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n,m,sum;
n = sc.nextInt();
while((n--)>0){
sum = 0;
m = sc.nextInt();
for(int i=0; i<m ; i++){
sum += sc.nextInt();
}
if(n==0){
System.out.println(sum);
}else{
System.out.println(sum);
System.out.println();
}
}
}
}







0 0
原创粉丝点击