62,614
社区成员
发帖
与我相关
我的任务
分享
public class Test {
private int a;
private int b;
public Test(int a, int b){
this.a = a;
this.b = b;
}
public int division()throws Exception{
if (b == 0) {
throw new Exception("除数不能为0!");
} else {
int resultNum = a/b;
return resultNum;
}
}
public static void main(String[] args) {
Test test = new Test(1,5);
try{
System.out.println(test.division());
}catch(Exception e){
e.getMessage();
}
}
}
public class test3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
test3 ff=new test3();
try {
ff.add(5, 0);
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
}
}
public void add(int a, int b)throws Exception{
if(b==0) {
throw new Exception("除数不能为0!");
}else {
System.out.println(a/b);
}
}
}