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("不及格");

    }

    }

    运行截图

  • 相关阅读:
    [Linux]
    [.Net]
    [.Net]
    [Linux]
    [Google]
    面向对象的7个基本设计原则
    windows SDK中的wininet写http客户端
    C++ 用libcurl库进行http通讯网络编程
    感悟
    关于Windows高DPI的一些简单总结
  • 原文地址:https://www.cnblogs.com/Zhanghaonihao/p/6098542.html
Copyright © 2011-2022 走看看