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

}

}

运行截图

 

posted on 2016-11-24 17:03  账号你好  阅读(278)  评论(0编辑  收藏  举报