zoukankan      html  css  js  c++  java
  • JAVA 异常处理

     

    import java.io.BufferedReader;

    import java.io.IOException;

    import java.io.InputStreamReader;

    Class  Geshiexception extends Exception{

           public Geshiexception(String a){

          super(a);

    }

    }

     

    public class Score {

             public static void main(String[] args) throws IOException{

             BufferedReader cin=new BufferedReader(new InputStreamReader(System.in));            //输入函数

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

             String str=cin.readLine();

             int t=0;

             double a;

             while(true){                //直到输入成绩的格式正确才停止

             try{                   //监控容易出问题的程序

                  for(int i=0;i<str.length();i++)

                  {

                       if(str.charAt(i)>'9'||str.charAt(i)<'0')

                      {

                              throw new Geshiexception("格式错误!");

                      }

             }

             a=Double.parseDouble(str);         //将String类型转成double类型

             if(a>100)

             throw new Geshiexception("格式错误!超值");

             break;

            }

             catch(Geshiexception e){         //异常处理

                   System.out.println(e);

                   System.out.println("请重新输入成绩:");

                   str=cin.readLine();

            }

          }

           if(a>=90)

           System.out.println("");

           else if(a<90&&a>=80)

           System.out.println("");

           else if(a<80&&a>70)

           System.out.println("");

           else if(a<70&&a>60)

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

           else if(a<60)

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

    }

    }

    运行截图

  • 相关阅读:
    SpringBoot笔记(一)
    线程同步(JAVA笔记-线程基础篇)
    图解JAVA线程的几个状态(JAVA笔记-线程基础篇)
    四种线程池的使用(JAVA笔记-线程基础篇)
    三种使用线程的方法(JAVA笔记-线程基础篇)
    图解数据结构——链表
    工作中Selenium常用方法汇总java版(工作笔记)
    【Spring】IoC容器
    【Spring】IoC容器
    【Spring】IoC容器
  • 原文地址:https://www.cnblogs.com/Zhanghaonihao/p/6098542.html
Copyright © 2011-2022 走看看