zoukankan      html  css  js  c++  java
  • java程序——输入判断成绩

    import java.util.*;
    
    class ExceptionOut extends Exception{
        
    }
    public class Score {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            
            String input,output;
            input = "请输入成绩:";
            System.out.println(input);
            try{
            Scanner sca = new Scanner(System.in);
            int score = sca.nextInt();
            if(score<60&&score>=0)
                output = "不及格!";
            else if(score>=60&&score<70)
                output = "及格!";
            else if(score>=70&&score<80)
                output = "中!";
            else if(score>=80&&score<90)
                output = "良!";
            else if(score>=90&&score<=100)
                output = "优!";
            else
                throw new ExceptionOut();
            }
            catch(ExceptionOut e){
                output = "成绩输入有误!";
                
            }
            catch(Exception e){
                output = "输入格式有误!";
            }
    
            System.out.println(output);
            
        }
    
    }
    结果截图:





     分析:先输入一个整型,然后判断优良,自定义一个ExceptionOut函数继承Exception父类,实现整型超出范围的错误抛出,然后用两个catch来接错误,一个是整型的范围不对,一个是输入的格式不对。

  • 相关阅读:
    RSA
    DES
    MD5
    增删改查
    [转]数据绑定之DataFormatString
    分页通用存储过程(未验证)
    浅谈sql中的in与not in,exists与not exists的区别
    [转]order by 1是什么意思?
    bak骗子公司
    Performance Considerations for Entity Framework 4, 5, and 6
  • 原文地址:https://www.cnblogs.com/xiaosongbiog/p/4960996.html
Copyright © 2011-2022 走看看