Anda di halaman 1dari 7

Test: Section 5 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indica
tes a correct answer.
Section 5 Quiz
(Answer all questions in this section)
1.
This keyword is used to instruct specific code when the
input for a switch statement that does not match any of the cases.
Mark fo
r Review
(1) Points
switch
case
break
default (*)
None of the above

Correct

Correct

2.
In an if-else construct the condition to be evaluated mu
st end with a semi-colon. True or false?
Mark for Review
(1) Points
True
False (*)

Correct

Correct
3.

Determine whether this boolean expression evaluates to t

rue or false:
!(3 < 4 && 6 > 6 || 6 <= 6 && 7 - 2 == 6)
(1) Points
True (*)
False

Mark for Review

Incorrect

Incorrect. Refer to Section 5 Lesson 1.

4.
In Java, each case seqment of a switch statement require
s the keyword break to avoid "falling through". Mark for Review
(1) Points
True (*)
False

Correct

Correct

5.
Which of the following could be a reason to use a switch
statement in a Java program?
Mark for Review
(1) Points
Because it allows the program to run certain segments of code and neglec
t to run others based on the input given. (*)
Because it allows the user to enter an input in the console screen and p
rints out a message that the user input was successfully read in.
Because it terminates the current loop.
Because it allows the code to be run through until a certain conditional
statement is true.

Correct

Correct

Page 1 of 3

Next

Summary

====================================================

Test: Section 5 Quiz


Review your answers, feedback, and question scores below. An asterisk (*) indica
tes a correct answer.
Section 5 Quiz
(Answer all questions in this section)
6.
r Review

The six relational operators in Java are:

Mark fo

(1) Points
>,<,=,!=,=<,=>
>,<,=,!,<=,>=
>,<,=,!=,<=,>=
>,<,==,!=,<=,>= (*)

Correct

Correct

7.
Which of the following expressions will evaluate to true
when x and y are boolean variables with opposite values?
I. (x || y) && !(x && y)
II. (x && !y) || (!x && y)
III. (x || y) && (!x ||!y)
(1) Points

Mark for Review

I only
II only
I and III
II and III
I, II, and III (*)

Correct

Correct
8.

Mark for Review


(1) Points
True
False (*)

The following prints Yes on the screen. True or false?

Correct

Correct

9.
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; 30; 5
3; 9; 11
5; 27; 8
4; 8; 27
3; 27; 8 (*)

Correct

Correct

10.
Mark for Review
(1) Points

What is the function of the word "break" in Java?

It exits the current loop or case statement. (*)


It does not exist in Java.
It stops the program from running.
It continues onto the next line of code.

Correct

Correct

Previous

Page 2 of 3

Next

Summary

==================================================
Test: Section 5 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indica
tes a correct answer.
Section 5 Quiz
(Answer all questions in this section)
11.
In a for loop the counter is not automatically increment
ed after each loop iteration. Code must be written to increment the counter. Tru
e or false?
Mark for Review
(1) Points
True (*)
False

Incorrect

Incorrect. Refer to Section 5 Lesson 2.

12.
The syntax below represents a valid initialization of a
for loop counter. True or False?
public class ForLoop {
public static void main (String args[])
{
for (int i=10; i <20; i++)
{System.out.println("i: "+i); }
}
}
Mark for Review
(1) Points
True (*)
False

Correct

Correct

13.
All of the following are essential to initializing a for
loop, except which one?
Mark for Review
(1) Points
Having an if statement. (*)
Having a conditional statement.

Initializing the iterator(i).


Updating the counter.

Correct

Correct
14.

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. (*)

Correct

Correct
15.

What is the output of the following code segment?

int num = 7;
while(num >= 0)
{
num -= 3;
}
System.out.println(num);
(1) Points

Mark for Review

0
-2 (*)
2
1

Correct

Correct

Previous

Page 3 of 3

Summary

==========================================================

Anda mungkin juga menyukai