From 2f9d059b2e3aef71fbc06c0aae32d215bed9f287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BD=98=E5=AE=87=E6=9D=B0?= <11806862+paocaimy@user.noreply.gitee.com> Date: Fri, 12 May 2023 15:46:40 +0000 Subject: [PATCH] =?UTF-8?q?=E6=BD=98=E5=AE=87=E6=9D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 潘宇杰 <11806862+paocaimy@user.noreply.gitee.com> --- ...02\345\270\270\344\275\234\344\270\232.md" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "07 \346\275\230\345\256\207\346\235\260/Music/20230512 \345\274\202\345\270\270\344\275\234\344\270\232.md" diff --git "a/07 \346\275\230\345\256\207\346\235\260/Music/20230512 \345\274\202\345\270\270\344\275\234\344\270\232.md" "b/07 \346\275\230\345\256\207\346\235\260/Music/20230512 \345\274\202\345\270\270\344\275\234\344\270\232.md" new file mode 100644 index 0000000..c2590fd --- /dev/null +++ "b/07 \346\275\230\345\256\207\346\235\260/Music/20230512 \345\274\202\345\270\270\344\275\234\344\270\232.md" @@ -0,0 +1,27 @@ +# 题目 + +用户输入两个整数,求这两个数的和,做好异常的处理 + +# 答案 + +``` +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner sca = new Scanner(System.in); + while (true){ + System.out.println("请输入整数"); + try { + int a= sca.nextInt(); + int b= sca.nextInt(); + System.out.println("和为:" + (a+b)); + break; + } catch (Exception e) { + System.out.println("请重新输入"); + sca=new Scanner(System.in); + } + } + } +} +``` \ No newline at end of file -- Gitee