当我输入M或F
时,我无法摆脱这个循环while(!optionGender.equals("M") || !optionGender.equals("F")){
System.out.println("Not an option, please try again");
optionGender = promptUser.nextLine();
optionGender = optionGender.toUpperCase();
}
答案 0 :(得分:2)
将您的条件||
改为&&
,
while(!optionGender.equals("M") && !optionGender.equals("F")){
System.out.println("Not an option, please try again");
optionGender = promptUser.nextLine();
optionGender = optionGender.toUpperCase();
}