
编写一个java程序实现如下功能
编写一个javaApplication程序,计算两个数相除并输出结果,使用2个catch子句,分别捕捉除数为0异常和参数输入有误异常...
编写一个java Application程序,计算两个数相除并输出结果,使用2个catch子句,分别捕捉除数为0异常和参数输入有误异常
展开
1个回答
展开全部
class zd {
int a, b;
Scanner sc = null;
public void s() {
sc = new Scanner(System.in);
a = sc.nextInt();
b = sc.nextInt();
try {
System.out.println(a / b);
} catch (ArithmeticException e) {
System.out.println("Divided by zero error!");
} catch (InputMismatchException e) {
System.out.println("Input type mismatch error!");
}
}
public static void main ( String args[] )
{
new zd().s();;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询