Lompat ke konten Lompat ke sidebar Lompat ke footer

Section 4 Quiz 2 - L3-L5

1. Which class is used to generate random numbers?

Number

Random (*)

Integer

Double

Correct

(1/1) Point

2. Which values are returned by the method nextBoolean();

Returns the next value.

An integer value.

Nothing is returned.

Either a true or false. (*)

Correct

(1/1) Point

3. You need to generate random integer values between 0 and 80 (inclusive). Which statement should you use?

nextInt(0-79);

nextInt(80);

nextInt();

nextInt(81); (*)

Correct

(1/1) Point

4. You need to generate random integer values in the range 2 through 10. This code fragment will produce the desired result.

Random r = new Random();

r.nextInt(9) + 2;

benar (*)

Palsu

Correct

(1/1) Point

5. String objects are immutable.

benar (*)

Palsu

Correct

6. A String is a sequence characters.

benar (*)

Palsu

Correct

(1/1) Point

7. The String class must be imported using java.lang.String;

benar

Palsu (*)

Correct

(1/1) Point

8. The replaceFirst() method replaces only the first occurrence of matching character pattern in a string.

benar (*)

Palsu

Correct

(1/1) Point

9. The String concat() method concatenates only String data types.

benar (*)

Palsu

Correct

(1/1) Point

10. What is the output?

public static void main(String args[]) {

   String alphaNumeric = "Java World!" + 8;

   System.out.println(alphaNumeric);

}

Compilation error.

Java World! + 8

Java World! 8

Java World!8 (*)

Correct

11. What is the output?

public static void main(String args[]) {

   String greeting = "Java World!";

   String w = greeting.substring(7, 11);

   System.out.println(w);

}

ld!

rld

orld!

rld! (*)

Correct

(1/1) Point

12. Which is NOT true?

A class can have multiple static methods.

Static methods must be of return void. (*)

Static methods can be invoked through an instance of a class

Static methods can be invoked through the class name.

Correct

(1/1) Point

13. Every method of the Math class returns a numerical result.

benar (*)

Palsu

Correct

(1/1) Point

14. A constant field, like Math.PI is used to represent a fixed value.

benar (*)

Palsu

Correct

(1/1) Point

15. Which two are the features of the Math class?

(Pilih semua jawaban yang benar)

Math methods can be invoked with Strings as arguments.

Common math functions like square root are taken care of in the language. (*)

You don’t have to worry about the data type returned from a Math method.

The Math methods can be invoked without creating an instance of a Math object. (*)

Correct

Posting Komentar untuk "Section 4 Quiz 2 - L3-L5"