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

            }

        }

    }

  • 相关阅读:
    mysql函数
    存储过程1
    linux下手动安装git教程
    python离线安装外部依赖包
    自动代码质量分析(GitLab+JenKins+SonarQube)
    Jenkins定时构建和轮询SCM设置说明
    jenkins
    linux在当前目录下根据文件名查找文件
    elastic search报错——“failed to obtain node locks”
    linux下rpm包安装、配置和卸载mysql
  • 原文地址:https://www.cnblogs.com/tangjindong/p/4966260.html
Copyright © 2011-2022 走看看