我是新手最近在学异常,照着例子编了一个程序怎么改都改不对,求各位指点
class myException extends Exception {
public myException(String wrongmessage){
super(wrongmessage);
}
}
class B {
public int divide(int a,int b) throws myException{
int m=0;
try {
if(b==0) throw new myException("除数不能为零");
else m=a/b;
}catch(myException e){
e.printStackTrace();
}
return m;
}
}
public class Exception_2 {
public static void main(String[] args){
B bb=new B();
if(bb.divide(6,0)==0) System.out.printf("除数不能为零\n");
else System.out.printf("divide=%d\n",bb.divide(6.0));
}
}编译结果是:无法将 B 中的 divide(int,int) 应用于 (double)
class myException extends Exception {
public myException(String wrongmessage){
super(wrongmessage);
}
}
class B {
public int divide(int a,int b) throws myException{
int m=0;
try {
if(b==0) throw new myException("除数不能为零");
else m=a/b;
}catch(myException e){
e.printStackTrace();
}
return m;
}
}
public class Exception_2 {
public static void main(String[] args){
B bb=new B();
if(bb.divide(6,0)==0) System.out.printf("除数不能为零\n");
else System.out.printf("divide=%d\n",bb.divide(6.0));
}
}编译结果是:无法将 B 中的 divide(int,int) 应用于 (double)
还有int m=0;这里是个中文的分号;细心一点啦^_^