I'm just wondering why this is not correct :
if ( !name.equals("abc") || !name.equals("cba") )`
And this is correct :
if ((!(name.equals("abc") || name.equals("cba") )))
thank you !
See Question&Answers more detail:osI'm just wondering why this is not correct :
if ( !name.equals("abc") || !name.equals("cba") )`
And this is correct :
if ((!(name.equals("abc") || name.equals("cba") )))
thank you !
See Question&Answers more detail:osThink about how the !
works.
Take !(a || b)
whats the truth table:
a=f b=f = !(f || f) = !(f) = t
a=f b=t = !(f || t) = !(t) = f
a=t b=f = !(t || f) = !(t) = f
a=t b=t = !(t || t) = !(t) = f
Now take (!a || !b)
a=f b=f = (!f || !f) = (t || t) = t
a=f b=t = (!f || !t) = (t || f) = t
a=t b=f = (!t || !f) = (f || t) = t
a=t b=t = (!t || !t) = (f || f) = f
Now take the correct way to distribute !
(!a && !b)
a=f b=f = (!f && !f) = (t && t) = t
a=f b=t = (!f && !t) = (t && f) = f
a=t b=f = (!t && !f) = (f && t) = f
a=t b=t = (!t && !t) = (f && f) = f
And for completeness sake take the same as (!a || !b)
!(a && b)
a=f b=f = !(f && f) = !(f) = t
a=f b=t = !(f && t) = !(f) = t
a=t b=f = !(t && f) = !(f) = t
a=t b=t = !(t && t) = !(t) = f