一道java题目 求告知哪里有错误啊啊啊啊啊
题目描述Yourtaskistocalculatethesumofsomeintegers.输入要求InputcontainsanintegerNinthefirstli...
题目描述
Your task is to calculate the sum of some integers.
输入要求
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.
输出要求
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.
假如输入
2
4 1 2 3 4
5 1 2 3 4 5
应当输出
10
15
这是我的代码
import java.util.Scanner;
public class 输入的数相加 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
for(int i = 0;i < N;i ++){
int M = sc.nextInt();
int [] a = new int[M];
int sum = 0;
for(int j = 0;j < M;j ++){
sum += a[j];
}
System.out.println(sum);
}
}
} 展开
Your task is to calculate the sum of some integers.
输入要求
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.
输出要求
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.
假如输入
2
4 1 2 3 4
5 1 2 3 4 5
应当输出
10
15
这是我的代码
import java.util.Scanner;
public class 输入的数相加 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
for(int i = 0;i < N;i ++){
int M = sc.nextInt();
int [] a = new int[M];
int sum = 0;
for(int j = 0;j < M;j ++){
sum += a[j];
}
System.out.println(sum);
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询