本帖最后由 赖永树 于 2014-12-29 20:52 编辑
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
-
- System.out.print("Enter two integer numbers: ");
-
- boolean done = false;
- int number1 = 0;
- int number2 = 0;
- while (!done)
- {
- try
- {
- number1 = input.nextInt();
- number2 = input.nextInt();
- done = true;
- }
- catch(Exception ex)
- {
- System.out.print("Incorrect input and re-enter two Integers: ");
- input.nextLine();
- continue;
- }
- }
- System.out.println("number1 and number2 is "+(number1+number2));
- input.close();
- }
复制代码
把循环放在外面,异常出现时 continue ,算了,还是敲吧。
|