CH 6 - ANSWER
A structure that allows repeated execution of a block of statements is a ___________. - ANSWERloop
A loop that never ends is a(n) ___________ loop - ANSWERinfinite
To construct a loop that works correctly, you should initialize a loop control ___________. -
ANSWERvariable
What is the output of the following code?
b = 1;
while(b < 4)
System.out.print(b + " "); - ANSWER1 1 1 1 1 1...
Why? - ANSWERWhen b is 1, the comparison in the while statement is true, so 1 prints. The
comparison is made
again, it is still true (because b is still 1), and 1 prints again. The value 1 prints infinitely
because b is never altered.
What is the output of the following code?
b = 1;
while(b < 4)
{
System.out.print(b + " ");
b = b + 1;
} - ANSWER1 2 3
Why?? - ANSWERWhen b is 1, the comparison in the while statement is true, so 1 is output. Then b
becomes 2,
, the Boolean evaluation is still true, and 2 is output. The b becomes 3, the Boolean evaluation is
true and 3 is output. Then b becomes 4, the Boolean expression is false, and the loop ends.
What is the output of the following code?
e = 1;
while(e < 4);
System.out.print(e + " "); - ANSWERnothing
WHYY - ANSWERThe semicolon at the end of the second line creates an empty loop body. The value
of e remains
1 forever; it keeps being compared to 4 infinitely
If total = 100 and amt = 200, then after the statement total += amt, ___________. - ANSWERtotal is
equal to 300
whyyyy - ANSWERThe statement total += amt is equivalent to total = total + amt
The prefix ++ is a ___________ operator. - ANSWERa. unary
If g = 5, then after h = ++g, the value of h is ___________. - ANSWER6
If m = 9, then after n = m++, the value of m is ___________. - ANSWER10
why? - ANSWERThe variable n receives the value of m prior to incrementing
If j = 5 and k = 6, then the value of j++ == k is ___________. - ANSWERfalse
whyyyyyyyyyy - ANSWERThe value of j++ is 5, so it does not equal k. After this statement executes, j
will be 6, but that
will be after the value of this comparison has been determined.
You must always include ___________ in a for loop's parentheses - ANSWER2 semicolons