package hh; import java.util.Scanner; public class ExceptionTest { public static void main(String[] args) { // TODO 自动生成的方法存根 Scanner input = new Scanner(System.in); System.out.println("请输入除数:"); int op1 = input.nextInt(); System.out.println("请输入被除数:"); int op2 = input.nextInt(); int result = 0; try { result = op1 / op2; } catch (ArithmeticException e) { e.printStackTrace(); } finally { System.out.println("异常处理"); } System.out.println(result); } }
这次简单一点