Skip to content
Advertisement

Multiple boolean values in if else statement is always false in Java

I am stuck to this method because of the if else condition says that

  • Condition usersInSales && usersInPayments is always false
  • Condition usersInSales && usersInLoans is always false
  • Condition usersInPayments && usersInLoans is always false

I tried different condition combinations and added the false values to try resolve it but it didn’t help. Please can I have some help? Thanks in advance

JavaScript

Advertisement

Answer

You have two solutions.

  1. Reorder your conditions, as others have shown. In your code by time you hit the && statements you have already dealt with the cases when one half is true. The && (two clauses) is more restrictive than a single clause.

  2. Alternatively, put the double clauses inside the previous ifs.

    JavaScript

becomes

JavaScript

This is a little more efficient and I think generally preferable.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement