diff --git "a/39 \345\220\264\346\241\220/20230513 Java \351\231\244\346\263\225\345\274\202\345\270\270.md" "b/39 \345\220\264\346\241\220/20230513 Java \351\231\244\346\263\225\345\274\202\345\270\270.md" new file mode 100644 index 0000000000000000000000000000000000000000..4378550e246c9a784315b9c96c9229bb0c5d7551 --- /dev/null +++ "b/39 \345\220\264\346\241\220/20230513 Java \351\231\244\346\263\225\345\274\202\345\270\270.md" @@ -0,0 +1,28 @@ +```java +import java.util.InputMismatchException; +import java.util.Scanner; +//除法算数的异常。 +public class MySum { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + while (true) { + try { + System.out.println("进入除法" + + "请输入a和b,用空格隔开:"); + int a = sc.nextInt(); + int b = sc.nextInt(); + System.out.println("a/b=" + a / b); + break; + } catch (ArithmeticException a) { + System.out.println("被除数不能为零."); + } catch (InputMismatchException a) { + System.out.println("输入错误,请检查输入。"); + sc.nextLine(); + } + } + + } +} + +``` +