异常处理

import java.util.Scanner;
public class ExceptionTest {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入除数:");
        int a;
        a = input.nextInt();
        System.out.println("请输入被除数:");
        int b;
        b = input.nextInt();
        int result = 0;
        try {
            result=a / b;
        } catch (ArithmeticException e) {
            e.printStackTrace();
        } finally {
            System.out.println("异常处理");
        }
        System.out.println(result);
        
    }}

你可能感兴趣的:(异常处理)