Boolean Logic & Operators
Selection Statements
Equivalence and Short Circuits
Object Comparison and Past Content
Trivia Time!
100

What is the result of: true && false?

false

100

What keyword follows an if statement to provide another conditional branch?

else if

100

Why does false && (x / 0 > 1) not crash?

Short-circuiting stops the second part from evaluating.

100

Which compares object contents in Java to determine if that are aliases?

==

100

What is the only metal that is liquid at standard room temperature?

Mercury

200

What is the result of: !(false || true)?

false

200

In an if / else if / else chain, how many branches will execute?

One.

Technically at most one.  If there is no else statement and all of the if and else if statements are false, then zero branches will execute!  

200

Rewrite using DeMorgan’s Law:

 !(x < 5 || y == 10)

(x >= 5 && y != 10)

200

2 PART QUESTION: What does the following evaluate to and why?

String s1 = new String("cat");
String s2 = new String("cat");
System.out.println(s1 == s2);

False!  These are two different objects.  The == operator checks if they have the same memory address, and these do not. 

200

Which country has the largest number of time zones in the world when including overseas territories?

France

300

Evaluate: (5 < 10) || (3 > 8 && 2 == 2)

true

300

What is the difference between:
 A) One if with many else ifs
 B) Several separate if statements

A) Only one branch can run.
B) Many branches can run if all conditions are true.

300

What is a short-circuit evaluation in terms of Java compilers.

Java evaluates only as much of an expression as needed to determine truth.

300

What shortcut operator updates a variable by adding to it?

 

+=

300

Which city was the first in the world to reach a population of 1 million people?

Rome

400

Apply DeMorgan’s Law to: !(a && b)

!a || !b

400

Which selection structure should you use when you have a condition that relies on another condition?

A Nested If Statement

400

 Identify the error:

if (str.length() > 0 && str.charAt(0) == 'A')

Which part risks a crash if str is null?

str.length() will cause the crash.  

This is a NullPointerException.  str.charAt would crash, but it is never encountered due to short circuit rules. 

400

Why does "hello".equals("HELLO") return false?

.equals is case-sensitive.

400

What is the hardest naturally occurring substance on Earth besides diamond (meaning the next hardest)?

Moissanite

500

Given:

int x = 0;
boolean result = (x !=0 && (10 / x) > 1);

Why will this not cause a division-by-zero error? 


Because && short-circuits.  When x != 0 is false, the right side (10 / x) never executes

500

What does the following print?

int n = 4;
if (n > 5)
    System.out.print("A");
else if (n > 3)
    System.out.print("B");
else
    System.out.print("C");

B

500

Convert to an equivalent expression using DeMorgan's Law:

 !(x == 7 || y != 3)

x != 7 && y == 3

500

What is the value of n after:

int n = 8;
n *= 2 + 3;

40

You should resolve the right side of the equals sign before you do the multiplication!  n *= 5 → 8 * 5 = 40.

500

In most versions of Greek mythology, which Titan is credited with creating mankind from clay?

Prometheus

(Some versions say Hephaistos)