杭电acm 1093 java

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

代码:import java.util.Scanner;

public class Main {

public static void main(String args[]) {

Scanner sc=new Scanner(System.in);

while(sc.hasNext()) {

int n;

int a;

a=sc.nextInt();

for(int j=0;j<a;j++)

{

int sum=0;

n=sc.nextInt();

int[] num=new int[n];

for(int i=0;i<n;i++)

{

num[i]=sc.nextInt();

}

for(int i=0;i<n;i++)

{

sum+=num[i];

}

System.out.println(sum);

}

}

}

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Java经典问题算法大全 /*【程序1】 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子...
    赵宇_阿特奇阅读 1,894评论 0 2
  • 50道经典Java编程练习题,将数学思维运用到编程中来。抱歉哈找不到文章的原贴了,有冒犯的麻烦知会声哈~ 1.指数...
    OSET我要编程阅读 7,067评论 0 9
  • Problem Description Your task is to Calculate a + b. Inpu...
    彦小忠阅读 113评论 0 1
  • 在C语言中,五种基本数据类型存储空间长度的排列顺序是: A)char B)char=int<=float C)ch...
    夏天再来阅读 3,392评论 0 2
  • Day01 class 例子{ public static void main(String[] args){ ...
    周书达阅读 1,119评论 0 0