What are the three basic types of decision-making statements in Java and how do they use boolean
expressions?
Instructor solution
The three basic types of decision-making statements in Java are if
, if-else
, and switch
. The if
and if-else
statements use boolean expressions to decide which block of code to execute. If the boolean expression evaluates to true
, the code within the if
or if-else
statement is executed. If it evaluates to false
, the code is skipped. The switch statement uses an expression (not necessarily boolean) to decide which case to execute.
You may exit out of this review and return later without penalty.