Its supposed to compare the the gender input to M or F and while it is neither of them ask the user to re-enter. It seems like it should work with the ! operator out front saying if gender is not equal to M or not equal to F then check. Problem i am getting is no matter what i enter it says it is invalid and stays in the loop forever.

This: while(!gender.equalsIgnoreCase("M") || !gender.equalsIgnoreCase("F")) is always true.

g="M":
g != "M" -- false
g != "T" -- true
false || true --> true

g="F":
g != "M" -- true
g != "F" -- false
true || false --> true

g = "X"
g != "M" -- true
g != "F" -- true
true || true --> true

The only way for that to be false if is g != "M" is false (meaning g is "M") and g != "F" is also false at the same time (meaning g is "F"). In other words, g has be both M and F and the same time for it to be false.

And print out isNotMale and isNotFemale while you're at it, in case there's any doubt left.

jawann jefferson
Greenhorn

Joined: Mar 06, 2012
Posts: 18

posted

0

Thanks for the great help. I did have to take another look at my condition logic. Instead of || i had to use &&. My conditions were constantly showing as true for the OR statement.
thanks a lot