From b10d2fab06551f266165372a80f8a08eacadfd7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A5=89=E5=BD=AC?= <3346955972@qq.com> Date: Fri, 12 May 2023 12:51:41 +0800 Subject: [PATCH] 20230512 --- .../20230512.md" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "33 \346\235\216\345\245\211\345\275\254/20230512.md" diff --git "a/33 \346\235\216\345\245\211\345\275\254/20230512.md" "b/33 \346\235\216\345\245\211\345\275\254/20230512.md" new file mode 100644 index 0000000..ae837ca --- /dev/null +++ "b/33 \346\235\216\345\245\211\345\275\254/20230512.md" @@ -0,0 +1,48 @@ +```java +import java.util.InputMismatchException; +import java.util.Scanner; + +public class Mach { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + boolean ok= true; + boolean yes = true; + int num1 = 1; + int num2 =1; + do { + System.out.println("请输入两个数:"); + try { + num1 = sc.nextInt(); + num2 = sc.nextInt(); + ok = false; + }catch (InputMismatchException e){ + System.out.println(e.getMessage()); + System.out.println("再次输入"); + sc.nextLine(); + } + }while (ok); + do { + try { + int result = num1/num2; + System.out.println("num1/num2 is"+result); + yes = false; + + }catch (ArithmeticException e){ + System.out.println(e.getMessage()); + boolean in = true; + do { + System.out.println("再次输入数字2"); + try { + num2 = sc.nextInt(); + in = false; + }catch (ArithmeticException e1){ + System.out.println(e1.getMessage()); + sc.nextLine(); + } + }while (in); + } + }while (yes); + + } +} +``` \ No newline at end of file -- Gitee