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谢谢各位!
{
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谢谢各位!
解决方案 »
- 静态与泛型可以放一起用么。
- 大神帮我看看这段代码有什么问题吧
- struts导入外部的工程
- 一个关于弹出菜单的问题```
- 郁闷,100分散!进者有分!
- java控制台输出老堵住,咋办??
- 我向文件中写入数据时,都会将链表中的数据写入两遍?(初学者的简单问题,今日结贴)
- 他们说是环境不正确:以知我的代码(极简的),编译没错,运行时出错:“java.lang.NoSuchMethodError: main /Exception in thread "main"
- 如何得到上传的图片的实际宽度和高度??
- 帮忙看下这两段代码有什么问题,关于线程同步问题
- Java集合类中为什么没有顺序Set,像ArrayList一样的,而是直接HashSet呢?
- 各位大牛,如何在JAVA里面实现倒排表
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 可以帮你很多.
你写的这个是我见过的最牛的一个
下面改好了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());
}
}
}
{
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());
}
}
}
主要都是符号和单词用错了.
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());
}
}
}