用户输入5个数据存到数组,计算输出5个数的和
import java.util.Arrays;
import java.util.Scanner;
// 用户输入5个数据存到数组,计算输出5个数的和
public class Work6 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int [] array = new int[5];
array[0] = scanner.nextInt();
array[1] = scanner.nextInt();
array[2] = scanner.nextInt();
array[3] = scanner.nextInt();
array[4] = scanner.nextInt();
int sum = 0;
for (int i = 0; i < array.length; i++) {
sum += array[i];
}
System.out.println("这五个数的和是"+sum);
scanner.close();
}
}