Java Java Basics Perfecting the Prototype Censoring Words - Using Logical ORs

Jason Hart
Jason Hart
1,089 Points

Quiz Question - Bob's Three Kids

For the "Using Logical ORs and ANDs" quiz, one of the questions is:

If Bob is 50, has 3 children, and works for a software company, what is the answer to this logical statement: age > 30 || children < 3 || isEmployed

The answer the quiz is looking for is True.

I thought it would be False as the number of his children (3) is equal to, not less than 3.

In Java, do you have to specify "less than or equal to" or does < account for that?

Thanks!

If Bob is 50, has 3 children, and works for a software company, what is the answer to this logical statement: age > 30 || children < 3 || isEmployed

The answer the quiz is looking for is True.

its clearly False but when i click False my answer is incorrect.

Jason Hart
Jason Hart
1,089 Points

Hi Jahangir. I too did not get this question at first. What I was missing is that || is OR. I was reading the question as "Is Bob over 30 years old AND has less than 3 children AND is employed." I answered False because Bob has 3 children not less than 3 children.

But II is OR so the question really is: Is Bob over 30 years old OR has less than 3 children OR is employed.

If Bob meets anyone one of those three, then the statement is True.

2 Answers

Dan Johnson
Dan Johnson
40,525 Points

In Java you use <= to specify less than or equal to. The result is true since only one condition has to be true for the entire expression to be true when using logical OR.

Jason Hart
Jason Hart
1,089 Points

Ah! That's what I missed. Makes sense. Thanks.

Tony Brackins
Tony Brackins
26,244 Points

Nice! I was like whaaaat!?? at 1st too lol

"If Bob is 50, has 3 children, and works for a software company, what is the answer to this logical statement." This statement is misleading. For the result to be true, all three conditions have to be true. I know the code is using Or (||) but the statement does not match the code. It should be like "If Bob is 50, has 3 children, or works for a software company, what is the answer to this logical statement." In this case, only one of the condition need to be met.