Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Review your answers, feedback, and question scores below.

An asterisk (*) indicates a correct


answer.

Section 6 Quiz
(Answer all questions in this section)
1. You need to calculate the squares of numbers from 1 to 5. Which of the items should be
present in your looping statement?
(1/1) Points
Initialization Expression , Condition Expression
Condition Expression , Update Expression
Initialization Expression , Update Expression
Initialization Expression , Condition Expression , Update Expression (*)
Correct

2. Each expression in the header section of a for loop is optional.


(1/1) Points
True (*)
False
Correct

3. Which two operators cannot be used as the conditional expression in a for loop?
(Choose all correct answers)
(1/1) Points
==
!< (*)
!> (*)
!=
<
Correct

4. The for loop provides a complicated way to iterate over a range of values.
(1/1) Points
True
False (*)
Correct

5. When is an update expression in a for loop executed?


(1/1) Points
Before the first iteration through the loop.
After each iteration through the loop. (*)
After two iterations through the loop.
Before each iteration through the loop.
Correct
Section 6 Quiz
(Answer all questions in this section)
6. What is the result?

public static void main(String[] args) {


for (;;) {
System.out.println("Welcome to Java");
}
}
(1/1) Points
Program prints “Welcome to Java” once.
Program prints “Welcome to Java” an infinite number of times. (*)
No error and no output.
Compilation error as expressions are missing in the for loop.
Correct

7. What is the output?

public static void main(String[] args) {


int num = 1;
while (num >= 200){
System.out.print(num + "" "");
num = num * 5;
}
}
(1/1) Points
No output. (*)
1 5 25 125 175
5 25 125
1 5 25 125
Correct

8. A do-while will always execute statements contained in the loop at least once.
(1/1) Points
True (*)
False
Correct

9. Which statement is true?


(1/1) Points
The counter which gets incremented determines the number of loop iterations is within the parentheses of a while
loop.
A while loop boolean expression is made up of a counter, increment, and test.
The boolean expression that determines the number of loop iterations is within the parentheses of a while
loop. (*)
A counter (i) is declared and initialized inside the while loop.
Correct

10. A post-test loop evaluates its condition at the end of the loop instead of the beginning.
(1/1) Points
True (*)

False
11. Which of the two are pre-test loops?
(Choose all correct answers)
(1/1) Points
do-while
forEach
for (*)
while (*)
Correct

12. Which two statements are true about the while loop.
(Choose all correct answers)
(1/1) Points
If the condition of a pre-test loop is false, the statements in the loop are never executed. (*)
If the condition of the loop is true initially, the statements are never executed.
The statement in a while loop will execute zero or more times. (*)
The statements of a while loop will execute one or more times.
Correct

13. Which is used to terminate a loop?


(1/1) Points
catch
break (*)
switch
continue
Correct

14. The purpose of adding comments is to increase the ability to understand the logic easily.
(1/1) Points
True (*)
False
Correct

15. A continue statement is used to skip the remaining statements in the body of a loop and
continue with the next iteration of the loop.
(1/1) Points
True (*)
False
Correct

You might also like