From d42d5c084a5573964ebfd9ee5225a14f3d534ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E4=BA=A8=E8=80=80?= <2640788668@qq.com> Date: Thu, 11 May 2023 10:14:24 +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 --- .../try catch.md" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "21 \345\215\242\344\272\250\350\200\200/try catch.md" diff --git "a/21 \345\215\242\344\272\250\350\200\200/try catch.md" "b/21 \345\215\242\344\272\250\350\200\200/try catch.md" new file mode 100644 index 0000000..06d36d2 --- /dev/null +++ "b/21 \345\215\242\344\272\250\350\200\200/try catch.md" @@ -0,0 +1,29 @@ +### 作业 + +```java +mport java.util.Scanner; + +public class Num { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + System.out.println(aandb(sc)); + } + public static int aandb(Scanner sc) { + while (true) { + try { + System.out.println("输入第一个数:"); + int a = sc.nextInt(); + System.out.println("输入第二个数:"); + int b = sc.nextInt(); + return a+b; + } catch (Exception e) { + System.out.println("输入整数"); + sc.nextLine(); + } + + } + + } +} +``` + -- Gitee