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("请输入正确数字:");

            }

        }

    }

  • 相关阅读:
    data-icon=""图片还可以是自定义的?
    orientationchange不管用啊
    menu({postion:{my:"left top"},at:"right bottom"})里的my与at会冲突吗
    关于position的疑惑
    Linux
    C++
    MATLAB
    SCE
    SFLA混合蛙跳算法
    memetic algorithm
  • 原文地址:https://www.cnblogs.com/tangjindong/p/4966260.html
Copyright © 2011-2022 走看看