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 0000000000000000000000000000000000000000..06d36d2d0403ac57e159149010b595b321b48219 --- /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(); + } + + } + + } +} +``` +