static boolean check(double money)
{
String scont, yes = "yes", no = "no";
boolean bcont;
if (money == 0) {
System.out.println("You are broke and can no longer play.");
bcont = false;
return bcont;
}
System.out.println("You have " + form.format(money) + " left.");
System.out.println("Would you like to continue playing? (Yes or no?)");
scont = in.nextLine();
if (scont.equalsIgnoreCase(yes)) {
bcont = true;
return bcont;
}
else if (scont.equalsIgnoreCase(no)) {
bcont = false;
return bcont;
}
else {
System.out.println("Invalid answer.");
bcont = check(money);
return bcont;
}
}
显然,这只是我程序中的一个单一功能。当它到达scont = in.nextLine();
它时,它会跳过用户输入并在主函数中中断函数所在的循环。