A good answer might be:


How much flour do you have?
6
How much sugar do you have?
4
Enough for cookies!
When execution got to the if statement, it found that
flour >= 4    --- true, because 6 >= 4
and
sugar >= 2    --- true, because 4 >= 2
Since both sides were true, the two part question gave us true.

AND Operator

The and operator && is used to insist that there is a true on both sides:

this side must be true  && this side must be true
If both sides are true, the entire expression is true. If either side (or both) are false, the entire expression is false. "&&" is called a logical operator because it combines two true/false values into a single true/false value.

                      +--------------+
true/false value      |              |
--------------------->|              |
                      |              |  true/false
                      |     &&       |--------------->
true/false value      |              |
--------------------->|              |
                      |              |
                      +--------------+


A compact way of saying what && does is:
  • true  && true  = true
  • false && true  = false
  • true  && false = false
  • false && false = false
The and-operator is used when every requirement is must be met.

QUESTION 5:

Look at the logical expression:

flour >= 4 && sugar >= 2 
What will the expression give us if flour is 2 and sugar is 0?

Click Here after you have answered the question