0% found this document useful (0 votes)
12K views

Quiz4 2

1. The code concatenates the string "Java" with "World", printing the result "JavaWorld". 2. String objects are immutable, so the original string is not changed by concatenation. 3. The replace method replaces all occurrences of a character in a string, so it prints "JAvA World!".

Uploaded by

Yulia Kendengis
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12K views

Quiz4 2

1. The code concatenates the string "Java" with "World", printing the result "JavaWorld". 2. String objects are immutable, so the original string is not changed by concatenation. 3. The replace method replaces all occurrences of a character in a string, so it prints "JAvA World!".

Uploaded by

Yulia Kendengis
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Section 4 Quiz 2 - L3-L5

(Answer all questions in this section)

1. What is the output of the following code?

public static void main(String args[]) {


String firstString = "Java";
firstString = firstString.concat("World");
System.out.println(firstString);
} Mark for Review
(1) Points

World

JavaWorld (*)

Java

Java World

Correct Correct

2. String objects are immutable. Mark for Review


(1) Points

True (*)

False

Incorrect Incorrect. Refer to Section 4 Lesson 3.

3. What is the output?

public static void main(String args[]) {


String greeting = "Java World!";
String w = greeting.replace("a", "A");
System.out.println(w);
} Mark for Review
(1) Points

JAvA World! (*)

JavA World!
Java World!

JAva World!

Correct Correct

4. The String class must be imported using java.lang.String; Mark


for Review
(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 4 Lesson 3.

5. The replaceFirst() method replaces only the first occurrence of


matching character pattern in a string. Mark for Review
(1) Points

True (*)

False

Correct Correct

Section 4 Quiz 2 - L3-L5


(Answer all questions in this section)

6. The indexOf() method returns the index value of a character in


the string. Mark for Review
(1) Points

True (*)

False

Correct Correct

7. A String is a sequence characters. Mark for Review


(1) Points
True (*)

False

Correct Correct

8. Using the Random class requires an import statement. Mark for


Review
(1) Points

True (*)

False

Correct Correct

9. 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; Mark for Review
(1) Points

True (*)

False

Incorrect Incorrect. Refer to Section 4 Lesson 4.

10. Which class is used to generate random numbers? Mark for Review
(1) Points

Double

Random (*)

Number

Integer
Correct Correct
11. Which values are returned by the method nextBoolean(); Mark for Review
(1) Points

An integer value.

Either a true or false. (*)

Returns the next value.

Nothing is returned.

Correct Correct

12. Which two are the features of the Math class? Mark for Review
(1) Points

(Choose all correct answers)

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

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

The Math methods can be invoked without creating an instance of a Math


object. (*)

Math methods can be invoked with Strings as arguments.

Correct Correct

13. All the methods in the Math class are static methods. Mark for
Review
(1) Points

True (*)

False
Correct Correct

14. What is the package name which contains Math class? Mark for
Review
(1) Points

java.lang (*)

java.net

java.io

java.awt

Correct Correct

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


value. Mark for Review
(1) Points

True (*)

False

Correct Correct

You might also like