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

  • 相关阅读:
    关于软件设计中遇到的问题
    关于power shell
    如果TChart的发生异常
    重温gof版《设计模式》中的创建型模式
    如何更好的使用cvs
    存储过程返回临时表的问题
    关于bugzilla与svn结合的配置注意事项
    VC知识点:如何用vc6调试CGI程序
    如何让应用程序托盘化
    符号表
  • 原文地址:https://www.cnblogs.com/jjking/p/11191101.html
Copyright © 2011-2022 走看看