Java How to Program, 11/e Multiple Choice Test Bank 3 of 8
d. int total = 0;
for (int i = 2; i < 20; total += i, i += 2) {}
Application: Compound Interest Calculations
5.4 Q4: Which statement prints the floating-point value 123.456 right justified with a field width of 10?
a. System.out.printf(“%d10.3”, 123.456);
b. System.out.printf(“%10.3d”, 123.456);
c. System.out.printf(“%f10.3”, 123.456);
d. System.out.printf(“%10.3f”, 123.456);
5.4 Q5: Which formatting flag indicates that the floating-point values should be output with a thousands
separator?
a. plus (+).
b. minus (–).
c. comma (,).
d. period (.).
Section 5.5 do…while Iteration Statement
5.5 Q1: Which of the following statements about a do…while iteration statement is true?
a. The body of a do…while loop is executed only if the terminating condition is true.
b. The body of a do…while loop is executed only once.
c. The body of a do…while loop is always executed at least once.
d. None of the above.
5.5 Q2: Which of the following will not help prevent infinite loops?
a. Include braces around the statements in a do…while statement.
b. Ensure that the header of a for or while statement is not followed by a semicolon.
c. If the loop is counter-controlled, the body of the loop should increment or decrement the counter as
needed.
d. If the loop is sentinel-controlled, ensure that the sentinel value is input eventually.
Section 5.6 switch Multiple-Selection Statement
Using a switch Statement to Count A, B, C, D and F Grades
5.6 Q1: For the two code segments below:
Segment A
int q = 5;
switch(q) {