From 952a5cf5e991b22c6d189e67b6faeb19dacbe15a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=98=8E=E5=81=A5?= <2161737470@qq.com> Date: Thu, 11 May 2023 09:44:57 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E5=8D=81=E5=9B=9B=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...02\345\270\270\344\275\234\344\270\232.md" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "04 \346\235\216\346\230\216\345\201\245/20230510 \345\274\202\345\270\270\344\275\234\344\270\232.md" diff --git "a/04 \346\235\216\346\230\216\345\201\245/20230510 \345\274\202\345\270\270\344\275\234\344\270\232.md" "b/04 \346\235\216\346\230\216\345\201\245/20230510 \345\274\202\345\270\270\344\275\234\344\270\232.md" new file mode 100644 index 0000000..b2b3891 --- /dev/null +++ "b/04 \346\235\216\346\230\216\345\201\245/20230510 \345\274\202\345\270\270\344\275\234\344\270\232.md" @@ -0,0 +1,29 @@ +## 作业 + +~~~ java +import java.util.InputMismatchException; +import java.util.Scanner; + +public class Demo1 { + public static void main(String[] args) throws InputMismatchException { + Scanner sc = new Scanner(System.in); + + while (true) { + try { + System.out.println("请输入第一个整数:"); + int num1 = sc.nextInt(); + + System.out.println("请输入第二个整数:"); + int num2 = sc.nextInt(); + System.out.println(num1 + num2); + break; + + } catch (InputMismatchException i) { + System.out.println("输入的数字有误,请重新输入!"); + //清空接收的缓存 + sc.nextLine(); + } + } + } +} +~~~ -- Gitee