zoukankan      html  css  js  c++  java
  • java多态与异常处理——动手动脑

    编写一个程序,此程序在运行时要求用户输入一个 整数,代表某门课的考试成绩,程序接着给出“不及格”、“及格”、“中”、“良”、“优”的结论。

    要求程序必须具备足够的健壮性,不管用户输入什 么样的内容,都不会崩溃。

    import java.util.*;

    public class Mark {

    public static void main(String[] args)

    {

    Scanner sc =new Scanner(System.in);

    int score=0;

    System.out.print("请输入成绩:"); 

            try

            {

          score=sc.nextInt();

              if(score>=0&&score<=59)

                 {

                   System.out.println("不及格");

                 }

                 if(score>=60&&score<=69)

                 {

                  System.out.println("及格");

                 }

                 if(score>=70&&score<=79)

                 {

                  System.out.println("中");

                 }

                 if(score>=80&&score<=89)

                 {

                  System.out.println("良");

                 }

                 if(score>=90&&score<=100)

                 {

                  System.out.println("优");

                 }

                 if(score<0||score>100)

                 {

                  System.out.println("输入的数字过大或过小");

                 }

                 else

                 {

                  System.out.println("");

                 }

            }

            catch(Exception e)

            {

             System.out.println("请输入正确数字:");

            }

        }

    }

  • 相关阅读:
    Oracle查询当前用户和当前用户下的所有表
    poj 1222EXTENDED LIGHTS OUT
    poj 1753 Flip Game
    老李分享:loadrunner用javavuser进行接口测试
    性能测试培训:帮你定位 Linux 性能问题的 18 个命令以及工具
    cf158B(水题)
    AC自动机讲解+[HDU2222]:Keywords Search(AC自动机)
    [BZOJ2120]:数颜色(分块?)
    赋值运算,拷贝运算,运算符重载
    Fraction to Recurring Decimal(STRING-TYPE CONVERTION)
  • 原文地址:https://www.cnblogs.com/tangjindong/p/4966260.html
Copyright © 2011-2022 走看看