From 8335ab61b8d9f5d1f9052dc82aa4fa2144ff9d63 Mon Sep 17 00:00:00 2001 From: pj3q7x5mz <1732875197@qq.com> Date: Thu, 17 Nov 2022 11:22:51 +0800 Subject: [PATCH] ADD file via upload --- ...常处理之try-catch之异常捕获.txt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Java异常处理之try-catch之异常捕获.txt diff --git a/Java异常处理之try-catch之异常捕获.txt b/Java异常处理之try-catch之异常捕获.txt new file mode 100644 index 0000000..d8695d2 --- /dev/null +++ b/Java异常处理之try-catch之异常捕获.txt @@ -0,0 +1,28 @@ + +import java.util.Scanner; + +public class ExcTest { + public static void main(String[] args) { + // 请在Begin-End间编写代码 + /********** Begin **********/ + // 第一步:接收给定的整数 + Scanner input=new Scanner(System.in); + int a = input.nextInt(); + int b = input.nextInt(); + int x; + // 第二步:求给定两个数的商,并捕获除数为0的异常 + try{ + x = a / b; + } + catch(Exception e){ + { + System.out.println("除数不能为0"); + } + } + if(b != 0){ + System.out.println(a / b); + } + /********** End **********/ + + } +} \ No newline at end of file