java编程题求助?
2个回答
2019-12-23
展开全部
简单一点的,类名自己改一下,我看不清
异常类:
public class ChushuException extends Exception{
public ChushuException() {
super();
}
public ChushuException(String message) {
super("异常就是我自己抛出去的:"+message);
}
}
除法:
class ChuFa{
public static double div(double a, double b) throws ChushuException{
if(b == 0){
throw new ChushuException("数值为0");
}
return a/b;
}
}
测试的main方法
public static void main(String[] args) throws Exception{
try{
System.out.println(ChuFa.div(1.2,0));
}catch (ChushuException e){
System.out.println("捕获除数数值为0异常:"+ e.getMessage());
}
}
异常类:
public class ChushuException extends Exception{
public ChushuException() {
super();
}
public ChushuException(String message) {
super("异常就是我自己抛出去的:"+message);
}
}
除法:
class ChuFa{
public static double div(double a, double b) throws ChushuException{
if(b == 0){
throw new ChushuException("数值为0");
}
return a/b;
}
}
测试的main方法
public static void main(String[] args) throws Exception{
try{
System.out.println(ChuFa.div(1.2,0));
}catch (ChushuException e){
System.out.println("捕获除数数值为0异常:"+ e.getMessage());
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询