我想询问用户是否要继续玩游戏。为此,我用过,
char choice;
do
{
System.out.println("Would you like to continue?(y/n)");
choice=sc.nextLine().charAt(0);
if (choice!='y' && choice!='n')
{
System.out.println("Invalid Entry");
}
}while (choice!='y' && choice!='n');
这项工作正常,我没有遇到任何问题,但这是正确的方法吗?