posts - 45,comments - 0,views - 4800
复制代码
public class Demo1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("学生人数:");
        int n = scanner.nextInt();

        double[] studentScores = new double[n];
        String[] studentNames = new String[n];
        int i = 0;
//录入姓名分数
for (i = 0; i < n; i++) { System.out.println("请输入学生姓名:"); String studentName = scanner.next(); System.out.println("请输入" + studentName + "的成绩:"); double inputScore = scanner.nextDouble();
//存入到数组中 studentScores[i]
= inputScore; studentNames[i] = studentName; }
//总分和平均分
double sum = 0; for (i = 0; i < n; i++) { System.out.println(studentNames[i] + "的成绩:" + studentScores[i]); } for (double score : studentScores) { sum += score; } System.out.println("总分为:" + sum + "\t平均分为:" + sum / n);
//最高分和最低分
//假设数组中第一个元素值为最大值或最小值
int maxIndex = 0; int minIndex = 0;
//依次比较
for ( i = 0; i < studentScores.length; i++) { if (studentScores[i] > studentScores[maxIndex]) { maxIndex = i; } if (studentScores[i] < studentScores[minIndex]) { minIndex = i; } } System.out.println("最高分:" + studentScores[maxIndex] + "\t姓名:" + studentNames[maxIndex]); System.out.println("最低分:" + studentScores[minIndex] + "\t姓名:" + studentNames[minIndex]); } }
复制代码

 

posted on   小贤看世界  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示