100% found this document useful (1 vote)
69 views4 pages

Java Scanner and Conditional Quiz

This document summarizes the results of a quiz on using scanners and conditional statements in Java. It lists 12 multiple choice questions from the quiz with the correct answers indicated by an asterisk. For each question, it indicates whether the user's answer was correct or incorrect and recommends reviewing a specific lesson if the answer was incorrect.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
69 views4 pages

Java Scanner and Conditional Quiz

This document summarizes the results of a quiz on using scanners and conditional statements in Java. It lists 12 multiple choice questions from the quiz with the correct answers indicated by an asterisk. For each question, it indicates whether the user's answer was correct or incorrect and recommends reviewing a specific lesson if the answer was incorrect.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Section 5 Using Scanner and Conditional

Statements
Test: Using Scanner and Conditional
Statements: Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates a
correct answer.

Section 1
(Answer all questions in this section)
[Link] will print if the following Java code is executed?
Mark for
Review
(1) Points

0
3 (*)
4
5

Incorrect. Refer to Section 5 Lesson 1.


[Link] of the following correctly initializes an instance of Scanner, called
Mark for
"in", that reads input from the console screen?
Review
(1) Points
Scanner in = new Scanner([Link]); (*)
Scanner in = new Scanner("[Link]");
Scanner in = Scanner([Link]);
[Link] in = new Scanner();

Incorrect. Refer to Section 5 Lesson 1.


[Link] of the two diagrams below illustrate the correct syntax for variables
Mark for
used in an if-else statement?
Review
(1) Points
Example A (*)
Example B

Incorrect. Refer to Section 5 Lesson 1.


[Link] an if-else construct, the condition to be evaluated must be contained
Mark for
within parentheses. True or False?
Review
(1) Points
True (*)
False

Correct
[Link] six relational operators in Java are:
Mark for
Review
(1) Points
>,<,=,!,<=,>=
>,<,=,!=,=<,=>
>,<,=,!=,<=,>=
>,<,==,!=,<=,>= (*)
Incorrect. Refer to Section 5 Lesson 1.
[Link] whether this boolean expression evaluates to true or false:
Mark for
!(3<4&&5>6||6<=6&&7-1==6)
Review
(1) Points
True
False (*)

Incorrect. Refer to Section 5 Lesson 1.


[Link] three logic operators in Java are:
Mark for
Review
(1) Points
!=,=,==
&&, ||, ! (*)
&&,!=,=
&,|,=

Incorrect. Refer to Section 5 Lesson 1.


[Link] 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.


[Link] Java, each case seqment of a switch statement requires the keyword
Mark for
break to avoid "falling through".
Review
(1) Points
True (*)
False

Correct
1The following code fragment properly implements the switch statement.
Mark for
[Link] or false?
Review
(1) Points
default(input)
switch '+':
answer+=num;
break;
case '-':
answer-=num;
break;
!default
[Link]("Invalid input");
True
False (*)

Incorrect. Refer to Section 5 Lesson 1.


1How would you use the ternary operator to rewrite this if statement?
Mark for
1.
Review
if (skillLevel > 5)
(1) Points
numberOfEnemies = 10;
else
numberOfEnemies = 5;
numberOfEnemies = ( skillLevel > 5) ? 5 : 10;
numberOfEnemies = ( skillLevel < 5) ? 10 : 5;
numberOfEnemies = ( skillLevel >= 5) ? 5 : 10;
numberOfEnemies = ( skillLevel >= 5) ? 10 : 5;
numberOfEnemies = ( skillLevel > 5) ? 10 : 5; (*)

Incorrect. Refer to Section 5 Lesson 1.


1How would you use the ternary operator to rewrite this if statement?
Mark for
2.
Review
if (gender == "male")
(1) Points
[Link]("Mr.");
else
[Link]("Ms.");
[Link]( (gender == "male") ? "Mr." : "Ms." ); (*)
[Link]( (gender == "male") ? "Ms." : "Mr." );
(gender == "male") ? "Mr." : "Ms." ;
(gender == "male") ? "Ms." : "Mr." ;

Correct

Page 1 of 1

You might also like