Page 254 - computer science (868) class 11
P. 254
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 would 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
6. What would be the output of the following?
String a = 1234;
System.out.println(a);
a. 1234 b. ‘1234’
c. “1234” d. Shows an error
B. Fill in the blanks:
1. The class String belongs to ………………… package.
2. The String method compareTo() returns ………………… when both the strings are equal.
3. ………………… method returns the total number of tokens in an object.
4. The String method equals() returns a ………………… type value.
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? #Ethical and Moral Reasoning
3. Define StringTokenizer class.
D. Unsolved Programs:
1. Write a program in Java to input the following quotes:
Honesty is the best policy.
A little progress each day adds up to big results.
Goodness is the only investment that never fails.
Now, print all the quotes in ascending order of number of vowels in each quote.
2. Write a program in Java to find the frequency of one string in another string:
Class name : frequency
Data Members
String sen : contains the string
String wd : contains the word to be checked
int count : stores the frequency of wd
Member Methods
void input() : enters sentence in sen and a word in wd
void find_freq() : finds the frequency of wd in sen
void display() : prints the counter variable
3. Write a program in Java to input a sentence and arrange words of the string in order of their lengths from shortest to longest.
252252 Touchpad Computer Science-XI

