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("很显然,这成绩是假滴!");
        }
      }
    }

  • 相关阅读:
    自我介绍
    工作流
    spring框架
    关于建立内部会议讨论规范的想法
    论文第3章:移动绘图平台的架构设计
    迭代器、推导式、函数式编程学习笔记
    Python装饰器学习(九步入门)
    Inkpad绘图原理浅析
    从零开始创建一个插件
    Entity Framework的启动速度优化
  • 原文地址:https://www.cnblogs.com/jjking/p/11191101.html
Copyright © 2011-2022 走看看