• 一维数组的练习


    从键盘输入的学生成绩,找出最高分, 并输出学生成绩等级

    成绩  >=最高分-10   等级 A

    成绩  >=最高分-20   等级 B

    成绩  >=最高分-30   等级 C

    其余                         等级 D

    import java.util.Scanner;
    public class TestScore {
        public static void main(String[] args) {
            Scanner s = new Scanner(System.in);
            System.out.println("输入学生个数");
            int count = s.nextInt();
            int[] scores = new int[count];
            int maxSocre = 0;
            System.out.println("输入成绩");
            for (int i = 0; i < scores.length; i++) {
                int score = s.nextInt();
                scores[i] = score;
                if (scores[i] > maxSocre) {
                    maxSocre = scores[i];
                }
            }
            // 遍历学生成绩数组, 根据差值 赋予相应等级 ,并输出
            System.out.println("最高分为:" + maxSocre);
            for (int i = 0; i < scores.length; i++) {
                char level;
                if (scores[i] >= maxSocre - 10) {
                    level = 'A';
                } else if (scores[i] >= maxSocre - 20) {
                    level = 'B';
                } else if (scores[i] >= maxSocre - 30) {
                    level = 'C';
                } else {
                    level = 'D';
                }
                System.out.println("student " + i + " score is " + scores[i] + " grade is " + level);
            }
        }
    }

    运行如下:

    All that work will definitely pay off
  • 相关阅读:
    vue 封装数据字典项翻译方法
    vue 判断是否为移动端
    elementUI 日期控件
    Laravel 数据库backup 导入/导出
    yarn 安装出现 git 443 网络错误解决思路
    nvm简介
    nrm简介
    npm简介
    python 时间序列学习笔记
    java常见面试题——java常见笔试题
  • 原文地址:https://www.cnblogs.com/afangfang/p/12459950.html
Copyright © 2020-2023  润新知