Q: Give the output of the following string functions:
"LANGUAGE".replace('A', '0');
"PROGRAM".compareTo("Program");
-
A
1. LONGUOGE 2. -32
-
B
L0NGU0GE 2. -32
-
C
1. Languoge 2. 32
-
D
1. LANGUOGE 2. 30
B
Answer:
B
Explanation:
Explanation:
"LANGUAGE".replace('A', '0');
Replaces all occurrences of 'A' with '0' in the string.
Result: "L0NGU0GE".
"PROGRAM".compareTo("Program");
Compares the strings lexicographically.
Java uses ASCII values, and the difference in case ('P' in uppercase vs. 'p' in lowercase) gives -32.
Related Topic:
Share Above MCQ