0
do{
try{
System.out.println("Please enter the publication year :");
year=keyboard.nextInt();
doneYear=true;
} catch(InputMismatchException e) {
System.out.println("Please enter a number.");
}
} while(!doneYear);
这不起作用。一旦我遇到第一个异常,它会无限循环。要求输入,直到他输入一个数字?
我想你需要'keyboard.next()'你的catch块 –
内作品。谢谢!! –