ACM Steps ---- Section1

這裏挑選的是兩個水題,輸入和輸出的練習


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();
}
}
}
}







發佈了50 篇原創文章 · 獲贊 4 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章