Page 441 - CA_Blue( J )_Class10
P. 441
8. Given the following code, what will be the output?
String s1 = "aaa";
System.out.println(s1.indexOf('a'));
a. 0 b. 1
c. 2 d. 3
9. What is the output of the following code?
String s = "Hello World";
System.out.println(s.substring(1, 7).lastIndexOf('O'));
a. 0 b. -1
c. 1 d. 3
10. Which method is used to remove leading and trailing whitespaces from a string?
a. trim() b. strip()
c. removeSpaces() d. clean()
B. Fill in the blanks.
1. A ………………… is a sequence of characters enclosed between double quotes.
2. The process of combining two strings is known as ………………….
3. The return type of the replace() method of the String class is ………………….
4. The trim() method removes ………………… from the current String object.
5. The ………………… method is used to convert any primitive value to string.
C. Answer the following questions:
1. Write a program to input a sentence and print the following:
(i) Number of words starting with “A” (ii) Number of vowels and consonants
2. Write a program to input a sentence and covert it to capital letters. Input a character and print the number of times the character
is present in the string. Also replace the character with “*” and print the new sentence.
Input:
Enter sentence: INDIA IS MY COUNTRY
Enter character: 'I'
Output:
Number of times 'I' present: 2
New sentence: *ND*A *S MY COUNTRY
3. Input a string and print the longest word in the string.
Input: Computer Applications deals with the application of computer in general life
Output: The longest word: Applications
4. Input a string and print the smallest word in the string.
Input: Computer Applications deals with the application of computer in general life
Output: The smallest word: in
5. Write a program to input a non-palindromic word and print the word in palindromic form.
Input : Enter a non-palindromic word: general
Output: The palindromic word is: generallareneg
6. Write a program to input a word and print the ASCII Value of each character or the word.
Input : ABCDE
Output: A=65
B=66
C=67
D=68
E=69
7. Input a full name and print the abbreviated name.
Input: Ram Kumar Sharma
Output: Sharma, R.K.
439
String Handling 439

