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
  • 相关阅读:
    [ECNU 1624] 求交集多边形面积
    [转] Java之ACM速成
    [swustoj 191] 迷宫逃离
    [Swustoj 24] Max Area
    PICK定理模板
    [HDU 1007] Quoit Design
    [转] 最近点对距离问题
    [POJ 2184] Cow Exhibition
    SGU 144.Meeting
    SGU 143.Long Live the Queen(女王万岁)
  • 原文地址:https://www.cnblogs.com/afangfang/p/12459950.html
Copyright © 2011-2022 走看看