Blake Havens - 1 month ago 15

Java Question

So I'm trying to check multiple booleans (6), and want to execute different code if more than one, two, three, etc. are true.

So here is an example:

`public static boolean x;`

public static boolean y;

public static boolean z;

public static boolean a;

public static boolean b;

public static boolean c;

public static int amtTrue;

//if x & y are true, then set amtTrue to 1

//if y & z AND x & y are true, then set amtTrue to 2;

//keep iterating though all possiblilites

What would be the most efficient way to do this?

Thanks for your time!

Answer

```
int i = 0;
for(boolean b : array)
if(b) i++;
switch(i){
case 0:
case 1:
case 2:
}
```