Page 320 - ComputerScience_Class_11
P. 320
}
}
Ans. 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);
}
}
Unsolved Questions
A. Tick ( ) the correct option.
1. Which of the following methods is used to join the strings together?
a. concat() b. append()
c. concatenate() d. Both a and b
2. If String s1="Java" and String s2="JAVA", what will be the output of s1.equals(s2)?
a. False b. True
c. Equal d. Error
3. What will be the output of the following:
String s1="Java"
s1.deleteCharAt(0);
a. Jav b. ava
c. Jva d. 0ava
4. We do not need to use the import command with the ………………… package.
a. util b. lang
c. io d. sql
5. If s1= "Nainital", then s1.insert(5, "bal") will show the output as:
a. Nainitalbal b. Nainbalital
c. Nainibaltal d. Naibalnital
B. Fill in the blanks.
1. hasMoreTokens() returns ………………… if there is a token left in the StringTokenizer object else it returns false.
2. The String method compareTo() returns ………………… when both the strings are equal.
3. ………………… method returns the total number of tokens in an object.
4. Character.isUpperCase(char) function returns true if the alphabet is in ………………… letters.
5. The compareTo() function returns a value less than zero if the first string is ………………… than the second string whereas it returns
a value greater than zero when the first string is ………………… than the second string.
C. Answer the following questions:
1. What is the use of the String class?
2. What do you mean by StringBuffer class?
3. Define StringTokenizer class.
4. Define the Character class and explain its methods.
5. Explain the purpose and usage of the length() function in Java.
6. Differentiate between the indexOf(char ch, int index) function and the lastIndexOf(char ch) function.
7. In which situations would you use the replace(char charToReplace, char charToInsert) function in Java?
8. Explain the append() method in Java. How does it work?
318 Touchpad Computer Science (Ver. 3.0)-XI

