Lompat ke konten Lompat ke sidebar Lompat ke footer

Section 5 Quiz

1. 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 );

}

Compilation error

I scored 1 point

I scored 1 point 10 points

I scored 10 points (*)

Correct

(1/1) Point

2. Which two are not logical operators?

(Pilih semua jawaban yang benar)

||

+ (*)

% (*)

!

&&

Correct

(1/1) Point

3. In the OR (||) test, if the first expression on the left hand side is true then there is no need to evaluate the second statement.

benar (*)

Palsu

Correct

(1/1) Point

4. In Java, an if statement can be nested inside another if statement.

benar (*)

Palsu

Correct

(1/1) Point

5. A String comparison with == compares the Strings’ locations in memory and not the content of the String.

benar (*)

Palsu

Incorrect. Refer to Section 5 Lesson 1.

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

benar (*)

Palsu

Correct

(1/1) Point

7. Which three are conditional statements?

(Pilih semua jawaban yang benar)

switch statement (*)

do while loop

if statement (*)

if/else statement (*)

for loop

Incorrect. Refer to Section 5 Lesson 1.

(0/1) Point

8. Which are used in a boolean expression?

(Pilih semua jawaban yang benar)

Variables (*)

Loops

Operators (*)

Errors

Correct

(1/1) Point

9. An if/else statement is used when you need to choose between two alternatives.

benar (*)

Palsu

Correct

(1/1) Point

10. How should Strings be compared?

==

=

~=

The equals() method (*)

Correct

11. 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 ");

   }

}

Bob is 43 (*)

No output

Bob is 43 Bob is 50

Bob is 50

Correct

(1/1) Point

12. A break statement causes control to transfer to the end of the switch statement.

benar (*)

Palsu

Correct

(1/1) Point

13. 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");

   }

}

Compilation error

Consonants (*)

Vowels

Vowels

Correct

(1/1) Point

14. Which two of the following data types can be used in a switch statement?

(Pilih semua jawaban yang benar)

String (*)

float

boolean

int (*)

Incorrect. Refer to Section 5 Lesson 3.

(0/1) Point

15. The switch statement is a more efficient way to write code when dealing with a large range of unknown values.

benar

Palsu (*)

Correct

Posting Komentar untuk "Section 5 Quiz"