package Chapter5.ShiLi.Demo1;
import java.util.*;
public class Test7 {
/**
* 多重catch块异常处理判断
* @param args
*/
public static void main(String[] args) {
try {
Scanner input = new Scanner(System.in);
System.out.println("请输入被除数:");
int num1 = input.nextInt();
System.out.println("请输入除数:");
int num2 = input.nextInt();
int sum = num1 / num2;
System.out.println(num1 + "/" + num2 + "=" + sum);
} catch (InputMismatchException e) {
System.out.println("出现错误:被除数和除数必须是整数。");
} catch (ArithmeticException e) {
System.out.println("除数不能为零。");
} catch (Exception e) { // Exception异常必须放在所有异常后面!!!
System.out.println("其他未知异常。");
} finally {
System.out.println("感谢使用本程序");
}
}
}