Page 319 - ComputerScience_Class_11
P. 319
2. Why does the original String not change after applying toLowerCase()?
a. Because Strings are dynamic b. Because Strings are immutable
c. Because Strings are case-sensitive d. Because Strings use StringBuffer
3. The function indexOf('a', 5) will start searching from:
a. Beginning of the string b. End of the string
c. Index 5 d. Index 0
4. Which class is used when Aman wants to modify the string using the delete() method?
a. Character b. String
c. StringBuffer d. System
Answers
1. b 2. b 3. c 4. c
G. Identify the error in the given codes and rewrite the correct code:
1. class Main {
public static void main(String[] args) {
String s1 = "Computer";
int len = s1.length;
System.out.println("Length = " + len);
}
}
Ans. class Main {
public static void main(String[] args) {
String s1 = "Computer";
int len = s1.length();
System.out.println("Length = " + len);
}
}
2. class Main {
public static void main(String[] args) {
StringBuffer s1= new StringBuffer("PRoGRAMMING");
s1.setcharAt(2,'O');
System.out.println(s1);
}
}
Ans. class Main {
public static void main(String[] args) {
StringBuffer s1= new StringBuffer("PRoGRAMMING");
s1.setCharAt(2,'O');
System.out.println(s1);
}
}
3. class Main {
public static void main(String[] args) {
String str1= "Java-";
String str2= "Programming";
String together= str1.Concat(str2);
System.out.println("The joined string is: " - together);
Strings 317

