package com.gao.test;
import java.util.Scanner;
/*
题目:
键盘录入十个学生的成绩,求和,求平均数
*/
public class TestDemo07 {
public static void main(String[] args) {
//功能:键盘录入十个学生的成绩,求和,求平均数
//定义一个int类型的数组,长度为10;
int[] scores=new int[10];
//定义一个求和的变量:
int sum = 0;
Scanner sc = new Scanner(System.in);
for(int i = 1; i<=10; i++){ //i控制循环的次数
System.out.print("请录入第"+i+"位同学的成绩:");
int score = sc.nextInt();
scores[i-1] = score;
sum += score;
}
System.out.println("十个学生的成绩之和是"+sum);
System.out.println("十个学生的成绩平均数是"+sum/10);
//求第6个学生的成绩:
System.out.println("第6个学生的成绩是:"+scores[5]+"分");
}
}
![]()