public void processing()
{
System.out.println("Please enter the amount of saving per month: ");
try
{
while(input.hasNext())
{
setSavingPermonth(input.nextDouble());
System.out.println("Please enter expected interest rate: ");
setInterestRate(input.nextDouble());
System.out.println("Please enter number of month for saving: ");
setNumberOfMonth(input.nextInt());
displayInputs();
System.out.println();
totalContibution();
totalSavingAmount();
System.out.println();
System.out.println("\nPlease enter the amount of saving per month: \n(or <Ctrl + D> to close the program)");
}
}
catch(InputMismatchException inputMismatchException)
{
System.err.println("Input must be numeric. \ntry again: ");
//**Anything need to done here in order to go back to setInterestRate()?**
}
}
我想回到异常捕获错误输入异常之前的位置,例如,我为 setInterestRate() 输入了一个字符串,但 Java 将我捕获到那里,并显示错误消息,问题:我该如何返回到那里以便我可以重新输入正确的数据?