请你分别求出每个数组的元素之和。
第一行有一个整数。
随后组数据。
每组的第一行有两个整数和
。
每组的随后行,每行有
个整数
。
保证。
输出行,每行一个整数,代表数组元素之和。
3 3 4 1 2 3 4 5 6 7 8 9 10 11 12 1 1 2024 3 2 1 1 4 5 1 4
78 2024 16
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
int t = 0;
if (in.hasNextInt()){
t = in.nextInt();
}
while(0 < t--){
int n = 0;
int m = 0;
if(in.hasNextInt()){
n = in.nextInt();
}
if(in.hasNextInt()){
m = in.nextInt();
}
long sum = 0;
int count = 0;
count = n*m;
while(0<count--){
if(in.hasNextInt()){
sum += in.nextInt();
}
}
System.out.println(sum);
}
in.close();
}
}