為什么在catch里加上input = new Scanner(System.in);能夠阻止無限循環
public static int inputCommand()
{
int a;
try
{
a = input.nextInt();
return a;
}catch(Exception e)
{
input = new Scanner(System.in);//阻止無限循環
//System.out.println("命令輸入錯誤!請根據提示輸入數字命令!");
return -1;
}
}
2019-08-06
拋出異常,然后處理異常,處理完之后進行下一步