我必须确保包含处理异常的语句,但是当我这样做时,变量 Amount 不会改变。帮助?
public static void main(String[] args){
AmwayTickets run = new AmwayTickets();
System.out.print(run.ticketAmount());
}
public int ticketAmount(){
System.out.println("Enter the amount of tickets you wish to purchase: ");
int amount = 0;
try {
amount = keyboard.nextInt();
}
catch (InputMismatchException e){
System.out.println("Invalid Amount");
ticketAmount();
return amount;
}
if (amount < 0){
System.out.println("Invalid Amount");
ticketAmount();
return amount;
}
return amount;
}