Self-Review Exercises 2
Self-Review Exercises
5.1 Fill in the blanks in each of the following statements:
a) Typically, statements are used for counter-controlled iteration and
statements for sentinel-controlled iteration.
b) The do…while statement tests the loop-continuation condition executing
the loop’s body; therefore, the body always executes at least once.
c) The statement selects among multiple actions based on the possible values of
an integer variable or expression, or a String.
d) The statement, when executed in an iteration statement, skips the remaining
statements in the loop body and proceeds with the next iteration of the loop.
e) The operator (with short-circuit evaluation) can be used to ensure that two
conditions are both true before choosing a certain path of execution.
f) If the loop-continuation condition in a for header is initially , the program
does not execute the for statement’s body.
g) Methods that perform common tasks and do not require objects are methods.
5.2 State whether each of the following is true or false. If false, explain why.
a) The default case is required in the switch selection statement.
b) The break statement is required in the last case of a switch selection statement.
c) The expression ((x > y) && (a < b)) is true if either x > y is true or a < b is true.
d) An expression containing the || operator is true if either or both of its operands are true.
e) The comma (,) formatting flag in a format specifier (e.g., %,20.2f) indicates that a value
f) To test for a range of values in a switch statement, use a hyphen (–) between the start
and end values of the range in a case label.
g) Listing cases consecutively with no statements between them enables the cases to per-
form the same set of statements.