Great work! Control flow allows Java programs to execute code blocks depending on Boolean expressions. What did we learn about control flow so far?
Boolean Operators:
&&
,||
, and!
are used to build Boolean expressions and have a defined order of operationsStatements:
if
,if
/else
, andif
/else if
/else
statements are used to conditionally execute blocks of codeTernary Conditional: a shortened version of an
if
/else
statement that returns a value based on the value of a Boolean expressionSwitch: allows us to check equality of a variable or expression with a value that does not need to be a Boolean
Instructions
Use the precedence rules to help you evaluate the Boolean expression in the single line comment above the tricky
variable.
Then, set the boolean
variable tricky
equal to the result (either true
or false
).
Change the Boolean expression in the if
statement so that your program will print out the code in the else
block instead.
Set the value of the int
variable subwayTrain
equal to the case
that will print "This is a Brooklyn bound train!"
to the console.