100% found this document useful (1 vote)
11K views5 pages

Section 5 Quiz

The document summarizes a quiz on Java programming concepts. It provides 15 multiple choice questions testing knowledge of switch statements, data types, conditional statements, operators, and string comparisons. For each question it indicates the correct answer and whether the user selected the right option.

Uploaded by

Dede M Iskandar
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)
11K views5 pages

Section 5 Quiz

The document summarizes a quiz on Java programming concepts. It provides 15 multiple choice questions testing knowledge of switch statements, data types, conditional statements, operators, and string comparisons. For each question it indicates the correct answer and whether the user selected the right option.

Uploaded by

Dede M Iskandar
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
You are on page 1/ 5

Test: JFo Section 5 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a
correct answer.

Section 5 Quiz
(Answer all questions in this section)
1. The switch statement is a more efficient way to write code when dealing with a large
range of unknown values.
Mark for Review

(1) Points
True
False (*)
Correct

2. What is the output?

char grade = 'A';


switch (grade) {
   case 'A':
      System.out.println("Congratulations!");    case 'B':
      System.out.println("Good work");
   case 'C':
      System.out.println("Average");
   case 'D':
      System.out.println("Barely passing");
   case 'F':
      System.out.println("Failed");
}

Mark for Review

(1) Points
A
Congratulations! Good Work Average Barely Passing Failed (*)
Congratulations!
Failed
Correct

3. Which two of the following data types can be used in a switch statement?
Mark for Review

(1) Points
float

String(*)
int(*)

boolean
Correct

4. What is the output?

public static void main(String args[]) {


   char ch ='c';
   switch(ch) {
     case 'a':
     case 'e':
     case 'i':
     case 'o':
     case 'u':
       System.out.println("Vowels");
       break;
     default:
       System.out.println("Consonants");
   }
}
Mark for Review

(1) Points
Vowels
Compilation error
Vowels
Consonants (*)
Correct

5. What are the possible values of a boolean data type in Java?


Mark for Review

(1) Points
0/1
good/bad
true/false (*)
yes/no
Correct
6. Which three are conditional statements?
Mark for Review

(1) Points
switch statement(*)

do while loop

if/else statement(*)
if statement(*)

for loop
Correct

7. What is the output?

public static void main(String[] args) {


   String name = "Java";
   String language = "Programming";
   String fullName = name + language;
   boolean test = fullName.equals(name + language);
   System.out.println(test);
}
Mark for Review

(1) Points
Java Programming
JavaProgramming
True (*)
False
Correct

8. The equal sign (=) is used to make an assignment, whereas the == sign merely
makes a comparison and returns a boolean.
Mark for Review

(1) Points
True (*)
False
Correct

9. What is the output?

public static void main(String[] args) {


   int age = 43;
   if (age == 43){
     System.out.print("Bob is 43 ");
   }
   if (age == 50){
     System.out.print("Bob is 50 ");
   }
}
Mark for Review

(1) Points
No output
Bob is 43 (*)
Bob is 50
Bob is 43 Bob is 50
Correct

10. How should Strings be compared?


Mark for Review

(1) Points
~=
The equals() method (*)
==
=
Correct
11. A String comparison with == compares the Strings’ locations in memory and not the
content of the String.
Mark for Review

(1) Points
True (*)
False
Correct

12. Which two are not logical operators?


Mark for Review

(1) Points
%(*)

&&

||

+(*)
Correct

13. In the AND (&&) test, if the first expression on the left hand side is false, then there
is no need to evaluate the second statement.
Mark for Review

(1) Points
True (*)
False
Correct
14. What is the result?

public static void main(String[] args) {


   int point = 10;
   String s = (point == 1 ? "point" : "points");
   System.out.println("I scored " +point +" " +s );
}
Mark for Review

(1) Points
I scored 1 point
Compilation error
I scored 1 point 10 points
I scored 10 points (*)
Correct

15. In a boolean expression which uses the && operator, what would make this
expression evaluate to true?

boolean x = (firstCondition && secondCondition);


Mark for Review

(1) Points
If the first condition is true, but the second condition is false
If both the first condition and second condition are false
If both the first condition and second condition are true (*)
If the first condition is false, but the second condition is true
Correct

You might also like