zoukankan      html  css  js  c++  java
  • Java——小程序练习一

    编写程序:由键盘输入给出一个百分制成绩,要求输出成绩等级’A’、’B’、’C’和’D’,90分以上为’A’,75~89为’B’,60~74为’C’,60分以下为’D’。

    最开始写的方法:没有注意到百分制的限定,缺少条件分析,思考不到位。

    public class Test01 {
      public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int score = scanner.nextInt();
        if (score>=90) {
          System.out.println("A");
        }else if (score>=75 && score<=89) {
          System.out.println("B");
        }else if (score>=60 && score<=74) {
          System.out.println("C");
        }else if (score<60) {
          System.out.println("D");
        }
      }
    }

    改正后:

    public class Test01 {
      public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int score = scanner.nextInt();
        if (score>=90&&score<=100) {
          System.out.println("A");
        }else if (score>=75 && score<=89) {
          System.out.println("B");
        }else if (score>=60 && score<=74) {
          System.out.println("C");
        }else if (score<60&&score>=0) {
          System.out.println("D");
        }else{
          System.out.println("很显然,这成绩是假滴!");
        }
      }
    }

  • 相关阅读:
    课程开始的第一次作业
    第四次寒假作业——实现五种语言的选择
    关于改良报告与学习总结(Ⅰ)
    Vue路由守卫之路由独享守卫
    Vue路由守卫之组件内路由守卫
    Vue中如何插入m3u8格式视频,3分钟学会!
    Vue中如何使用less
    第一章 初识爬虫
    【JQuery】注册中实现图片预览
    【Python】多种方式实现生成验证码
  • 原文地址:https://www.cnblogs.com/jjking/p/11191101.html
Copyright © 2011-2022 走看看