Your browser has JavaScript turned off. This page is best viewed with Javascript enabled. Certain functions on this site will not work, and some style sheets will not load. Check your browser preferences to enable JavaScript.

Teach Yourself Java

Lesson 3 Quiz

1. Which of the following could not be used as the Boolean in a conditional?

    (isCar is a Boolean variable, num is an int variable, text is a string variable)
if (isCar)
if (num <= 5)
if (num = 5)
if (text == "mine")

2. If you want your conditional to depend on two conditions BOTH being true, what is the proper notation to put between the two Boolean statements?
&
&&
|
||

3. Which of the following means that in order for the conditional to happen, either x must be less than 3 or y must be greater than or equal to 4?
if ((x < 3) && (y > 4))
if (x < 3 y >= 4)
if ((x < 3) || (y > = 4))
if ((x > 3) || (y < = 4))

4. Which of the following will cancel Church if there is an ice storm and have Church on as scheduled otherwise?
       (assume “iceStorm” is a boolean that is true if there is an ice storm and false otherwise)


if (iceStorm)
{
     NoChurch();
}
else if (!iceStorm)
{
     Church();
}

if (!iceStorm)
{
     Church();
}
else if (iceStorm)
{
     NoChurch();
}

else(!iceStorm)
{
     NoChurch();
}

if(iceStorm)
{
     NoChurch();
}
else()
{
     Church();
}

5. Else means:
In all other cases
It is a type of boolean
Then do this
None of the Above