为什么这个处理异常的程序这么写不行?
毕业设计
1
package exercise_13;
public class Exercise13_2 {
/**
* @param args
*/
public static void main(String[] args) {
java.util.Scanner input=new java.util.Scanner(System.in);
int num1 = 0,num2=0;
System.out.println("Please enter two integers:");
try{
num1=input.nextInt();
}catch(Exception ex){
System.out.println("You num is wrong,please enter again");
input.nextInt();
};
try{
num2=input.nextInt();
}catch(Exception ex){
System.out.println("Wrong input,input again ");
input.nextInt();
};
System.out.println(num1+num2);
}
}
发表回复