6.定义要给长度为5的数组,用于存储学生的成绩,成绩从键盘输入存储到数组中 (1) 将所有的成绩倒序打印输出 (2) 计算学生的平均成绩 (3) 键盘输入一个成绩s, 打印成绩>s的成绩有哪些?
package day06作业九月二十三; import java.util.Scanner; /*6.定义要给长度为5的数组,用于存储学生的成绩,成绩从键盘输入存储到数组中 (1) 将所有的成绩倒序打印输出 (2) 计算学生的平均成绩 (3) 键盘输入一个成绩s, 打印成绩>s的成绩有哪些?*/ public class 第六题 { public static void main(String[] args) { // TODO Auto-generated method stub double[] score = new double[5]; Scanner scanner = new Scanner(System.in); while (true) { System.out.println("请输入5个学生成绩"); for (int i = 0; i < score.length; i++) { System.out.println("请给第" + (i + 1) + "个学生输入成绩:"); score[i] = scanner.nextDouble(); } System.out.println("倒序输出所有成绩"); for (int i = score.length - 1; i >= 0; i--) { System.out.println(score[i]); } System.out.println("计算学生的平均成绩"); int sum = 0; for (int i = 0; i < score.length; i++) { sum += score[i]; } double ping = sum / score.length; System.out.println("平均成绩为" + ping); System.out.println("键盘输入s"); double s = scanner.nextDouble(); System.out.println("比" + s + "大的有"); for (int i = 0; i < score.length; i++) { if (score[i] > s) { System.out.println(score[i]); } } } } }