循环字符串检查

时间:2017-11-18 16:51:07

标签: java

当我输入M或F

时,我无法摆脱这个循环
while(!optionGender.equals("M") || !optionGender.equals("F")){
            System.out.println("Not an option, please try again");
            optionGender = promptUser.nextLine();
            optionGender = optionGender.toUpperCase();

        }

1 个答案:

答案 0 :(得分:2)

将您的条件||改为&&

while(!optionGender.equals("M") && !optionGender.equals("F")){
                System.out.println("Not an option, please try again");
                optionGender = promptUser.nextLine();
                optionGender = optionGender.toUpperCase();
   }