Handling Multiple Boolean Combinations
boolean, boolean-logic, combinations, java
Solution
One option would be to basically build a bitmask:
int mask = (a ? 1 : 0) |
(b ? 2 : 0) |
(c ? 4 : 0) |
(d ? 8 : 0) |
(e ? 16 : 0);
System.out.println(statements[mask]);
... where `statements` is an array of length 32. So in your case, `statements[31]` would be "All trues", and `statements[30]` would be "Some Text" etc.
Problem
I have 5 boolean variables a,b,c,d and e. So for each different combination of true and false of each variable there is a different print statement. Say for example: a b c d e --- Print Statements T T T T T -- Print All trues T T T T F -- Print Some Text T T T F F -- Print Some other text ........ There could be 32 different possible combinations. I'm writing a java code. So the question is for every condition there should be a different statement printed out. So what could be the best possible solution to handle this instead of the regular if statements which makes the code more confusing and unmanageable?