• Java小练习 用数组存储学生成绩并按规则评定


    import java.util.Scanner;
    
    public class scoreForm {
        public static void main(String[] args) {
            //使用Scanner读取学生个数
            System.out.println("请输入学生人数");
            Scanner scan = new Scanner(System.in);
            int num = scan.nextInt();
            //创建数组,存储学生成绩
            int[] arr = new int[num];
            //给数组中元素赋值
            for (int i = 0; i < arr.length; i++) {
                System.out.println("第" + (i + 1) + "位学生成绩是");
                arr[i] = scan.nextInt();
            }
            //获取最高分,即数组中最大值
            int max = arr[0];
            for (int i = 0; i < arr.length; i++) {
                if (max < arr[i]) {
                    max = arr[i];
                }
            }
            System.out.println("最高分是" + max);
            //根据规则评定学生成绩
         for (int i = 0; i < arr.length; i++) {
          if (arr[i] >= max - 10) {
            lvl='A';
          } else if (arr[i] >= max - 20) {
            lvl='B';
          } else if (arr[i] >= max - 30) {
             lvl='C';
          } else {
            lvl='D';
           }
       System.out.println("第" + (i + 1) + "位学生等级是"+lvl);
        }
       } 

    }
     
  • 相关阅读:
    TensorRT推理加速基于Tensorflow(keras)的uff格式模型(文件准备)
    pandas_format06
    docker01
    pandas_dataformat03
    pandas_dataformat02
    pandas_series04
    pandas_format05
    pandas_format04
    pandas_dataframe01
    pandas_series03
  • 原文地址:https://www.cnblogs.com/xianghaoran/p/12219809.html
Copyright © 2020-2023  润新知