Quiz5
1.In a for loop,
the counter is
automatically
incremented
after each
loop
iteration.
True or
False?
Mark for Review
(1) Points
True
False (*)
Correct
2. A counter used in a for loop cannot be initialized within the
For loop statement. True or False?
Mark for Review
(1) Points
True
False (*)
Incorrect. Refer to Section 5
Lesson 2.
3. What is one significant difference between a while loop
and a do-while loop?
Mark for Review
(1) Points
A DO-WHILE loop does not exist in Java and a
WHILE loop does.
A DO-WHILE loop will always execute the code at
least once, even if the conditional statement for the
WHILE is never true. A WHILE loop is only executed
if the conditional statement is true. (*)
A DO-WHILE loop includes an int that serves as a
counter and a WHILE loop does not.
There is no difference between a DO-WHILE loop and
a WHILE loop.
Correct
4. Why are loops useful?
Mark for Review
(1) Points
They save programmers from having to rewrite code.
They allow for repeating code a variable number of
times.
They allow for repeating code until a certain argument
is met.
All of the above. (*)
Incorrect. Refer to Section 5
Lesson 2.
5. Which of the following best describes a while loop?
Mark for Review
(1) Points
A loop that contains a segment of code that is executed
before the conditional statement is tested.
A loop that executes the code at least one time even if
the conditional statement is false.
A loop that is executed repeatedly until the conditional
statement is false. (*)
A loop that contains a counter in parenthesis with the
conditional statement.
Correct
6.How many
times will
the
following
loop be
executed?
What is the
value of x
after the
loop has
finished?
What is the
value of
count after
the loop
has
finished?
int count =
17;
int x = 1;
while(count
> x){
x*=3;
count-=3;
}
Mark for Review
(1) Points
5; 27; 8
3; 9; 11
5; 30; 5
3; 27; 8 (*)
4; 8; 27
Incorrect. Refer to Section 5 Lesson
2.
7. What is the function of the word "break" in Java?
Mark for Review
(1) Points
It does not exist in Java.
It exits the current loop or case statement. (*)
It continues onto the next line of code.
It stops the program from running.
Incorrect. Refer to Section 5 Lesson
2.
8. How would you use the ternary operator to rewrite this if
statement?
if (skillLevel > 5)
numberOfEnemies = 10;
else
numberOfEnemies = 5;
Mark for Review
(1) Points
numberOfEnemies = ( skillLevel >= 5) ? 5 : 10;
numberOfEnemies = ( skillLevel > 5) ? 5 : 10;
numberOfEnemies = ( skillLevel < 5) ? 10 : 5;
numberOfEnemies = ( skillLevel >= 5) ? 10 : 5;
numberOfEnemies = ( skillLevel > 5) ? 10 : 5; (*)
Incorrect. Refer to Section 5 Lesson
1.
9. In an if-else construct, the condition to be evaluated must be
contained within parentheses. True or False?
Mark for Review
(1) Points
True (*)
False
Incorrect. Refer to Section 5 Lesson
1.
10. The three logic operators in Java are:
Mark for Review
(1) Points
&&, !=, =
!=, =, ==
&, |, =
&&, ||, ! (*)
Correct
11.switch
statements
work on
all input
types
including,
but not
limited to,
int, char,
and
String.
True or
false?
Mark for Review
(1) Points
True
False (*)
Correct
12. Which of the following could be a reason to use a switch
statement in a Java program?
Mark for Review
(1) Points
Because it terminates the current loop.
Because it allows the user to enter an input in the console
screen and prints out a message that the user input was
successfully read in.
Because it allows the code to be run through until a
certain conditional statement is true.
Because it allows the program to run certain segments of
code and neglect to run others based on the input given.
(*)
Incorrect. Refer to Section 5 Lesson
1.
13. This keyword is used to instruct specific code when the input
for a switch statement that does not match any of the cases.
Mark for Review
(1) Points
switch
case
break
default (*)
None of the above
Incorrect. Refer to Section 5 Lesson
1.
14. What is the difference between the symbols = and == ?
Mark for Review
(1) Points
The symbol = is used in if statements and == is used in
loops.
The symbol == is used to assign values to variables and
the = is used in declarations.
The = is use to assign values to variables and the ==
compares values. (*)
There is no difference.
Incorrect. Refer to Section 5 Lesson
1.
15. Which of the following correctly matches the switch
statement keyword to its function?
Mark for Review
(1) Points
(Choose all correct answers)
switch: identifies what element will be compared to the
element of the case statements to find a possible match
(*)
switch: tells the compiler the value to compare the input
against
case: signals what code is executed if the user input
matches the specified element (*)
default: signals what code to execute if the input does not
match any of the cases (*)
if: records the user's input and sends it to the case
statements to find a possible match
Incorrect. Refer to Section 5 Lesson
1.

Quiz5

  • 1.
    Quiz5 1.In a forloop, the counter is automatically incremented after each loop iteration. True or False? Mark for Review (1) Points True False (*) Correct 2. A counter used in a for loop cannot be initialized within the For loop statement. True or False? Mark for Review (1) Points True False (*) Incorrect. Refer to Section 5 Lesson 2. 3. What is one significant difference between a while loop and a do-while loop? Mark for Review (1) Points A DO-WHILE loop does not exist in Java and a WHILE loop does. A DO-WHILE loop will always execute the code at least once, even if the conditional statement for the WHILE is never true. A WHILE loop is only executed if the conditional statement is true. (*) A DO-WHILE loop includes an int that serves as a counter and a WHILE loop does not. There is no difference between a DO-WHILE loop and a WHILE loop. Correct 4. Why are loops useful? Mark for Review (1) Points They save programmers from having to rewrite code. They allow for repeating code a variable number of times. They allow for repeating code until a certain argument is met. All of the above. (*) Incorrect. Refer to Section 5 Lesson 2. 5. Which of the following best describes a while loop? Mark for Review (1) Points A loop that contains a segment of code that is executed before the conditional statement is tested. A loop that executes the code at least one time even if the conditional statement is false.
  • 2.
    A loop thatis executed repeatedly until the conditional statement is false. (*) A loop that contains a counter in parenthesis with the conditional statement. Correct 6.How many times will the following loop be executed? What is the value of x after the loop has finished? What is the value of count after the loop has finished? int count = 17; int x = 1; while(count > x){ x*=3; count-=3; } Mark for Review (1) Points 5; 27; 8 3; 9; 11 5; 30; 5 3; 27; 8 (*) 4; 8; 27 Incorrect. Refer to Section 5 Lesson 2. 7. What is the function of the word "break" in Java? Mark for Review (1) Points It does not exist in Java. It exits the current loop or case statement. (*) It continues onto the next line of code. It stops the program from running. Incorrect. Refer to Section 5 Lesson 2. 8. How would you use the ternary operator to rewrite this if statement? if (skillLevel > 5) numberOfEnemies = 10; else numberOfEnemies = 5; Mark for Review (1) Points
  • 3.
    numberOfEnemies = (skillLevel >= 5) ? 5 : 10; numberOfEnemies = ( skillLevel > 5) ? 5 : 10; numberOfEnemies = ( skillLevel < 5) ? 10 : 5; numberOfEnemies = ( skillLevel >= 5) ? 10 : 5; numberOfEnemies = ( skillLevel > 5) ? 10 : 5; (*) Incorrect. Refer to Section 5 Lesson 1. 9. In an if-else construct, the condition to be evaluated must be contained within parentheses. True or False? Mark for Review (1) Points True (*) False Incorrect. Refer to Section 5 Lesson 1. 10. The three logic operators in Java are: Mark for Review (1) Points &&, !=, = !=, =, == &, |, = &&, ||, ! (*) Correct 11.switch statements work on all input types including, but not limited to, int, char, and String. True or false? Mark for Review (1) Points True False (*) Correct 12. Which of the following could be a reason to use a switch statement in a Java program? Mark for Review (1) Points Because it terminates the current loop. Because it allows the user to enter an input in the console screen and prints out a message that the user input was successfully read in. Because it allows the code to be run through until a certain conditional statement is true. Because it allows the program to run certain segments of code and neglect to run others based on the input given. (*) Incorrect. Refer to Section 5 Lesson 1.
  • 4.
    13. This keywordis used to instruct specific code when the input for a switch statement that does not match any of the cases. Mark for Review (1) Points switch case break default (*) None of the above Incorrect. Refer to Section 5 Lesson 1. 14. What is the difference between the symbols = and == ? Mark for Review (1) Points The symbol = is used in if statements and == is used in loops. The symbol == is used to assign values to variables and the = is used in declarations. The = is use to assign values to variables and the == compares values. (*) There is no difference. Incorrect. Refer to Section 5 Lesson 1. 15. Which of the following correctly matches the switch statement keyword to its function? Mark for Review (1) Points (Choose all correct answers) switch: identifies what element will be compared to the element of the case statements to find a possible match (*) switch: tells the compiler the value to compare the input against case: signals what code is executed if the user input matches the specified element (*) default: signals what code to execute if the input does not match any of the cases (*) if: records the user's input and sends it to the case statements to find a possible match Incorrect. Refer to Section 5 Lesson 1.