# Thread: arrays with booleans

1. Originally Posted by Norm
The OP said he was NOT allowed to use loops to solve this.
Ok, fine with me (although I don't understand the reason behind it); simply unroll the loop and use four if-statements like this:

Java Code:
```if (array[0]) count++;
if (array[1]) count++;
if (array[2]) count++;
if (array[3]) count++;```
... and test the value of 'count' at the end; trying to combine the truth values in the array results in an if-statements with 16 clauses which I find even sillier than the solution above ;-)

kind regards,

Jos

2. Originally Posted by JosAH
Ok, fine with me (although I don't understand the reason behind it);
Since it is a course, there are probably a few restrictions on what they can and can't do. When I was stuck in a beginner Python course last year, I was allowed to do whatever I wanted on the assignments for the most part ('cause my teacher was nice), but if the assignment said "solve this using the methods used in class thus far," I wasn't able to use anything more advanced.

3. Member
Join Date
Oct 2010
Posts
45
Rep Power
0
ok so i finally figured it out thanks sorry if i was a pain i am just not that good at java yet
here was my final code

Java Code:
```int count =0;
if (b[0]) count++;
if (b[1]) count++;
if (b[2]) count++;
if (b[3]) count++;
if (count > 1)
onlyone = false;
else
onlyone = true;```
Last edited by hoosierfan24; 10-04-2010 at 12:33 AM. Reason: changed my mind

4. Did your assignment allow you to use an int as counter?

5. Member
Join Date
Oct 2010
Posts
45
Rep Power
0
yes it did.
my class is through eimacs.com the ap computer science course if you are familiar with it

Page 2 of 2 First 12

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•