class Ex2 extends Exception
{
 Ex2(String msg)
 {
  super(msg);
  }
}
class MyEx
{
 private int x;
 void setX(int x)
 {
  this.x=x;
 }
 void f1() throws Ex2
 {
  if(x==13)
   throw new Ex2(“I don’t like 13!”);
 else if(x==4)
   throw new Ex2(“I don’t like 4!”);
 else
   system .out.println(100/x);
}
public static void main(Sstring args[ ])
{
 MyEx a=new MyEx();
 try 
 {
  a.steX(5);
  //a.setX(13);
//a.setX(4);
//a.setX(0);
a.f1();
}
 catch(Ex e)
 {
  Sytem .out.println(“get message:”+e.getMessage());
 }
}文件名:Ex.java谢谢各位!

解决方案 »

  1.   

    @SuppressWarnings("serial")
    public class Ex2 extends Exception { Ex2(String msg) {
    super(msg);
    }
    }class MyEx {
    private int x; void setX(int x) {
    this.x = x;
    } void f1() throws Ex2 {
    if (x == 13)
    throw new Ex2("I don’t like 13!");
    else if (x == 4)
    throw new Ex2("I don’t like 4!");
    else
    System.out.println(100 / x);
    } public static void main(String args[]) {
    MyEx a = new MyEx();
    try {
    a.setX(5);
    // a.setX(13);
    // a.setX(4);
    // a.setX(0);
    a.f1();
    } catch (Ex2 e) {
    System.out.println("get message:" + e.getMessage());
    }
    }
    }还是换用 eclipse 写吧.  你的拼写错误..还有标点符号错误很多. 用 eclipse 可以帮你很多.  
      

  2.   


    你写的这个是我见过的最牛的一个
    下面改好了class Ex2 extends Exception
    {
     Ex2(String msg)
     {
      super(msg);
      }
    }
    public class MyEx
    {
     private int x;
     void setX(int x)
     {
      this.x=x;
     }
     void f1() throws Ex2
     {
      if(x==13)
       throw new Ex2("I don’t like 13!");
     else if(x==4)
       throw new Ex2("I don’t like 4!");
     else
       System.out.println(100/x);
    }
    public static void main(String args[ ])
    {
     MyEx a=new MyEx();
     try 
     {
      a.setX(5);
      //a.setX(13);
    //a.setX(4);
    //a.setX(0);
    a.f1();
    }
     catch(Ex2 e)
     {
      System.out.println("get message:"+e.getMessage());
     }
    }
    }
      

  3.   

    class Ex2 extends Exception
    {
     Ex2(String msg)
     {
      super(msg);
      }
    }
    class MyEx
    {
     private int x;
     void setX(int x)
     {
      this.x=x;
     }
     void f1() throws Ex2
     {
      if(x==13)
       throw new Ex2("I don’t like 13!");
     else if(x==4)
       throw new Ex2("I don’t like 4!");
     else
       System.out.println(100/x);
    }
    public static void main(String args[ ])
    {
     MyEx a=new MyEx();
     try 
     {
      a.setX(5);
      //a.setX(13);
    //a.setX(4);
    //a.setX(0);
    a.f1();
    }
     catch(Exception e)
     {
      System.out.println("get message:"+e.getMessage());
     }
    }
    }
    主要都是符号和单词用错了.
      

  4.   

    class Ex2 extends Exception {
    Ex2(String msg) {
    super(msg);
    }
    }class My {
    private int x; void setX(int x) {
    this.x = x;
    } void f1() throws Ex2 {
    if (x == 13)
    throw new Ex2("I don’t like 13!");
    else if (x == 4)
    throw new Ex2("I don’t like 4!");
    else
    System.out.println(100 / x);
    } public static void main(String args[]) {
    My a = new My();
    try {
    a.setX(5);
    // a.setX(13);
    // a.setX(4);
    // a.setX(0);
    a.f1();
    } catch (Ex2 e) {
    System.out.println("get message:" + e.getMessage());
    }
    }
    }