From 79cd466a17ffb7af607ded54dd361807b39dbe82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=94=A1=E7=9B=9F?= <3098697928@qq.com> Date: Fri, 12 May 2023 16:28:54 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 蔡盟 <3098697928@qq.com> --- ...02\345\270\270\344\275\234\344\270\232.md" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "04 \350\224\241\347\233\237/14 \345\274\202\345\270\270\344\275\234\344\270\232.md" diff --git "a/04 \350\224\241\347\233\237/14 \345\274\202\345\270\270\344\275\234\344\270\232.md" "b/04 \350\224\241\347\233\237/14 \345\274\202\345\270\270\344\275\234\344\270\232.md" new file mode 100644 index 0000000..c2590fd --- /dev/null +++ "b/04 \350\224\241\347\233\237/14 \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