题目
输入数字N,然后输入N个数,计算这N个数的和。
输入描述:
第一行输入一个整数N(0≤N≤50),第二行输入用空格分隔的N个整数。
输出描述:
输出为一行,为第二行输入的“N个整数之和”的计算结果。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan1 = new Scanner(System.in);
int a=scan1.nextInt();
//Scanner scan2 = new Scanner(System.in);
int sum=0;
if (scan1.hasNext()) {
for (int i =0;i<a;i++){
int[] n = new int[a];
n[i]=scan1.nextInt();
sum=sum+n[i];
}
//scan2.close();
System.out.println(sum);
}
scan1.close();
}
}