views:

82

answers:

3

Hi all,
I have a java program where I want to validate if any of 3 booleans is false. I want to figure out the smallest expression I can write to check against the permutations.

if(!(needsWork && (needsApproval || isAdmin) ))

I think this is enough to make sure that if any of the 3 booleans is false I want to stop processing. However, I have the sneaking suspicion I am missing something.

+2  A: 
if(!(needsWork & needsApproval & isAdmin))
fabrizioM
+7  A: 

Would if (!needsWork || !needsApproval || !isAdmin) not work? Java supports short-circuit evaluation.

Phil Hunt
I was going for more readable, which is why I put the ! outside a parens
Woot4Moo
Phil Hunt
thanks that what I was looking for
Woot4Moo
Glad to be of assistance!
Phil Hunt
Ill mark this as the answer in a few minutes when it allows me too.
Woot4Moo