import java.util.Scanner;
import java.util.InputMismatchException;

public class TestException {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a, b;
        try {
            System.out.print("请输入被除数");
            a = input.nextInt();
            System.out.print("请输入除数");
            b = input.nextInt();
            System.out.println("两数相除的结果为:" + a / b);
        } catch (InputMismatchException e) {
            System.out.println("你输入的不是数字,在这里必须输入数字");
        } catch (ArithmeticException e) {
            System.out.println("输入错误,除数不能为零");
            System.out.println(e.getMessage());

        } catch (Exception e) {
            System.out.println("程序出错了");
        } finally {
            System.out.println("无论是否出现异常,这里都会执行");

        }
    }
}

 

相关文章:

  • 2022-01-31
  • 2022-01-06
  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-14
  • 2022-12-23
  • 2021-11-11
  • 2021-12-16
  • 2021-08-16
  • 2021-11-12
  • 2022-12-23
相关资源
相似解决方案