1

I cant get out of this loop when i enter M or F

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

        }
3
  • 2
    || should be && Commented Nov 18, 2017 at 16:52
  • still not working Commented Nov 18, 2017 at 16:55
  • The conditions inside while are opposite to each other, So no matter what input you give one condition will be set to true. As mentioned in the above comment by @4castle || should be replaced by && Commented Nov 18, 2017 at 16:55

1 Answer 1

2

Change your condition || by &&,

while(!optionGender.equals("M") && !optionGender.equals("F")){
                System.out.println("Not an option, please try again");
                optionGender = promptUser.nextLine();
                optionGender = optionGender.toUpperCase();
   }
Sign up to request clarification or add additional context in comments.

2 Comments

@DanielChen are you using m or f instead of M or F.
@DanielChen better to use equalsIgnoreCase instead of equals. It will check for M as well as m.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.