Section 6 Quiz
1. The initialization expression initializes the loop and it is executed only once, as the loop begins.
benar (*)
Palsu
Correct
(1/1) Point
2. You want to compute the sum of all the marks of a given subject. Which approach will you choose?
Looping (*)
switch statement
if statement
if/else statement
Incorrect. Refer to Section 6 Lesson 1.
(0/1) Point
3. A for loop is also called a definite loop
benar (*)
Palsu
Incorrect. Refer to Section 6 Lesson 1.
(0/1) Point
4. The for loop provides a complicated way to iterate over a range of values.
benar
Palsu (*)
Incorrect. Refer to Section 6 Lesson 1.
(0/1) Point
5. Looping continues as long as the boolean expression in the for loop is false.
benar
Palsu (*)
Incorrect. Refer to Section 6 Lesson 1.
6. What is the result?
public static void main(String[] args) {
for (;;) {
System.out.println("Welcome to Java");
}
}
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
(1/1) Point
7. Which statement is true?
The counter which gets incremented determines the number of loop iterations is within the parentheses of a while loop.
The boolean expression that 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.
A counter (i) is declared and initialized inside the while loop.
Correct
(1/1) Point
8. Which statement is NOT true about do-while loops?
Statements in the loop are executed once initially, and then the condition is evaluated.
The number of times a do-while loop is executed is dependent upon the value of the counter variable. (*)
Statements in the loop are executed repeatedly until the condition becomes false.
Statements in the loop are executed once until the condition becomes false.
Incorrect. Refer to Section 6 Lesson 2.
(0/1) Point
9. After the loop is terminated, the statement immediately following the loop body is executed.
benar (*)
Palsu
Correct
(1/1) Point
10. A while loop is often used with Scanner input as you don't know many times you'll need to re-prompt the user if they type bad data.
benar (*)
Palsu
Correct
11. Which two statements are true about the while loop.
(Pilih semua jawaban yang benar)
The statements of a while loop will execute one or more times.
The statement in a while loop will execute zero or more times. (*)
If the condition of the loop is true initially, the statements are never executed.
If the condition of a pre-test loop is false, the statements in the loop are never executed. (*)
Correct
(1/1) Point
12. Which statement is false about infinite loop?
An infinite loop is a commonly the result of a syntax error. (*)
An infinite loop is generally caused by a programming mistake.
An infinite loop is a code which will execute until the user interrupts the program
The body of a while loop eventually must make the condition false to avoid infinite loop.
Correct
(1/1) Point
13. 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.
benar (*)
Palsu
Correct
(1/1) Point
14. What is the result?
public static void main(String[] args) {
for (int var1 = 0; var1 < 2; var1++) {
for (int var2 = 0; var2 < 2; var2++) {
if (var2 == 2) {
continue;
}
System.out.println("var1:" + var1 + ", var2:" + var2);
}
}
}
var1: 0, var2: 0
var1: 0, var2: 1
var1: 1, var2: 0
var1: 1, var2: 1
(*)
var1: 0, var2: 0
var1: 0, var2: 1
var1: 0, var2: 2
var1: 1, var2: 0
var1: 1, var2: 1
var1: 1, var2: 2
var1: 2, var2: 0
var1: 2, var2: 1
var1: 2, var2: 2
var1: 0, var2: 0
var1: 0, var2: 1
var1: 1, var2: 0
var1: 1, var2: 1
var1: 2, var2: 0
var1: 2, var2: 1
var1: 0, var2: 0
var1: 1, var2: 1
var1: 2, var2: 0
Correct
(1/1) Point
15. Which is used to terminate a loop?
break (*)
continue
catch
switch
Correct
NYOBA KE 2
1. Which two statements are true about the break statement?
(Pilih semua jawaban yang benar)
The execution of the program will continue with the statement following the loop-statement. (*)
When a break statement is executed inside a loop, the loop-statement is terminated immediately and comes out of the program.
When a break statement is executed inside a loop, the loop-statement is terminated immediately. (*)
The execution of the program will stop at the statement following the loop-statement.
Correct
(1/1) Point
2. 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.
benar (*)
Palsu
Correct
(1/1) Point
3. The only way to exit a loop is for the loop condition to evaluate to false.
benar
Palsu (*)
Correct
(1/1) Point
4. Which statement will produce the output: 2, 4, 6, 8, 10?
for (int i = 1; i < 10; i += 2) {
System.out.print(i + " ");
}
for (int i = 0; i < 8; i += 2) {
System.out.print(i + " ");
}
for (int i = 0; i < 10; i += 2) {
System.out.print(i + " ");
}
for (int i = 2; i <= 10; i += 2) {
System.out.print(i + " ");
} (*)
Correct
(1/1) Point
5. You want to compute the sum of all the marks of a given subject. Which approach will you choose?
Looping (*)
if/else statement
if statement
switch statement
Correct
6. Which is not a looping statement in Java?
for
while
do-while
switch (*)
Correct
(1/1) Point
7. Which two are valid syntax to create a for loop?
(Pilih semua jawaban yang benar)
for(int i = 10 i >= 0; i++ ) {
System.out.println("i="+i);
}
for(int i = 10; i >= 0; i++ ) {
System.out.println("i="+i);
} (*)
for(int i = 10, i >= 0, i++ ) {
System.out.println("i="+i);
}
for(int i = 10; i >= 0; ) {
System.out.println("i="+i);
} (*)
Correct
(1/1) Point
8. When is an update expression in a for loop executed?
After each iteration through the loop. (*)
After two iterations through the loop.
Before each iteration through the loop.
Before the first iteration through the loop.
Correct
(1/1) Point
9. In the given syntax of for loop, which part represents the header section?
for (initialization; condition; update) {
// Code statement(s) }
for (initialization; condition; update) { Code statement(s) }
for (initialization; condition; update) { }
for (initialization; condition; update) (*)
Code statement(s)
Correct
(1/1) Point
10. After the loop is terminated, the statement immediately following the loop body is executed.
benar (*)
Palsu
Correct
11. What is the output?
public static void main(String[] args) {
int num = 1;
while (num >= 200){
System.out.print(num + "" "");
num = num * 5;
}
}
No output. (*)
1 5 25 125 175
1 5 25 125
5 25 125
Correct
(1/1) Point
12. Which statement is NOT true about do-while loops?
Statements in the loop are executed once initially, and then the condition is evaluated.
Statements in the loop are executed once until the condition becomes false.
Statements in the loop are executed repeatedly until the condition becomes false.
The number of times a do-while loop is executed is dependent upon the value of the counter variable. (*)
Correct
(1/1) Point
13. Which of the two are pre-test loops?
(Pilih semua jawaban yang benar)
while (*)
for (*)
do-while
forEach
Incorrect. Refer to Section 6 Lesson 2.
(0/1) Point
14. A pre-test loop evaluates the condition prior to execution of the loop.
benar (*)
Palsu
Correct
(1/1) Point
15. The while loop continually executes a block of statements while a particular condition is false.
benar
Palsu (*)
Correct
Posting Komentar untuk "Section 6 Quiz"