diff --git "a/10 \344\275\231\346\264\262/20230512 \345\274\202\345\270\270\344\275\234\344\270\2321.md" "b/10 \344\275\231\346\264\262/20230512 \345\274\202\345\270\270\344\275\234\344\270\2321.md" new file mode 100644 index 0000000000000000000000000000000000000000..a9a52f0dff3f8211252ed4aa2d61ffc241708c42 --- /dev/null +++ "b/10 \344\275\231\346\264\262/20230512 \345\274\202\345\270\270\344\275\234\344\270\2321.md" @@ -0,0 +1,27 @@ +# 题目 + +用户输入两个整数,求这两个数的和,做好异常的处理 + +# 答案 + +``` +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + while (true){ + System.out.println("请输入整数"); + try { + int a= sc.nextInt(); + int b= sc.nextInt(); + System.out.println("和为:" + (a+b)); + break; + } catch (Exception e) { + System.out.println("请重新输入"); + sc=new Scanner(System.in); + } + } + } +} +``` \ No newline at end of file