class MyException extends Exception
{
public MyException()
{

}
public MyException(String s)
{
super(s);
}
}
class abnormity14
{
    public String grade(int score)throws MyException
    {
     if(score>=0&&score<=100)
     {
     return "正常";
     }
     else
     {
     throw new MyException("错误输入");
     }
    }
}
public class abnormity15
{
public static void main(String args[])
{
abnormity14 ab=new abnormity14();
try
{
String s=ab.grade(68);
System.out.println(s);
}
catch(MyException e)
{
System.out.println("异常信息为:"+e.getMessage());
}
}
}
这段程序怎么也运行时弹出一个奇怪的窗口咯,呵呵,刚入门,不太懂哦。

解决方案 »

  1.   

    我运行了一下,没有任何奇怪的窗口啊,打印正常class MyException extends Exception 

    public MyException() 
    { } 
    public MyException(String s) 

    super(s); 


    class abnormity14 

        public String grade(int score)throws MyException 
        { 
        if(score>=0&&score <=100) 
        { 
        return "正常"; 
        } 
        else 
        { 
        throw new MyException("错误输入"); 
        } 
        } 

    class abnormity15 

    public static void main(String args[]) 

    abnormity14 ab=new abnormity14(); 
    try 

    String s=ab.grade(-100); 
    System.out.println(s); 

    catch(MyException e) 

    System.out.println("异常信息为:"+e.getMessage()); 


      

  2.   

    来推荐一下java基础视频教程在线听:http://www.cdlanhai.com/zxst/
      

  3.   

    不应该有什么奇怪的窗口啊,楼主在哪里运行的?是不是Eclipse弹出的窗口啊,比如提示有错误或者没保存什么的。