zoukankan      html  css  js  c++  java
  • 一维数组的练习

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

    成绩  >=最高分-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
  • 相关阅读:
    Shiro理解与总结
    spark教程(14)-共享变量
    Hive 教程(十)-UDF
    multivariate_normal 多元正态分布
    windows 安装 python 踩坑记录
    EM 算法(三)-GMM
    EM 算法(二)-KMeans
    EM 算法(一)-原理
    sklearn-GDBT
    集成学习-Boosting 模型深度串讲
  • 原文地址:https://www.cnblogs.com/afangfang/p/12459950.html
Copyright © 2011-2022 走看看