From 723894e9aae457bc8b23381d8bc43cab8772c974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=AE=8F=E8=BE=BE?= <12071445+ma-hongda@user.noreply.gitee.com> Date: Thu, 11 May 2023 03:14:42 +0000 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 马宏达 <12071445+ma-hongda@user.noreply.gitee.com> --- .../\345\274\202\345\270\270.md" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "48 \351\251\254\345\256\217\350\276\276/\345\274\202\345\270\270.md" diff --git "a/48 \351\251\254\345\256\217\350\276\276/\345\274\202\345\270\270.md" "b/48 \351\251\254\345\256\217\350\276\276/\345\274\202\345\270\270.md" new file mode 100644 index 0000000..79a2d98 --- /dev/null +++ "b/48 \351\251\254\345\256\217\350\276\276/\345\274\202\345\270\270.md" @@ -0,0 +1,19 @@ +### 用键盘输入两个整数,并求和;如果输入的不是整数用异常去处理 + +import java.util.Scanner; +public class D1 { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + while (true) { + System.out.println("请输入整数"); + try { + int a1 = sc.nextInt(); + int a2 = sc.nextInt(); + System.out.println("两个整数的和是:"); + System.out.println(a1+a2); + break; + } catch (Exception e) { + System.out.println("只能输入整数,请重新输入"); + } + } + } -- Gitee