Page 321 - ComputerScience_Class_11
P. 321
D. Higher Order Thinking Skills (HOTS)
1. In a text processing application, you are working with a StringBuilder object that contains a large block of text. You need to
remove a portion of the text from position 5 to 10. How would you use the delete() method to achieve this? Explain the steps and
provide a code example.
2. In a string manipulation tool, you need to replace the character at index 3 of a given string with a new character, say ‘X’. How
would you achieve this using the setCharAt() method of the StringBuilder class?
E. Case Study-based questions.
Text Editor with String Manipulation
You are developing a text editor that allows the user to modify text. The user has the ability to:
1. Delete a range of characters from the text.
2. Modify a specific character at a given position.
The program should perform these operations using the delete() and setCharAt() methods from the StringBuilder class.
Scenario:
• Input: The text editor initially takes the string “Java Programming”.
• Process:
1. The user wants to delete the characters from index 4 to 10, removing the word “Program”.
2. The user wants to change the character at index 0 from ‘J’ to ‘j’.
• Output:
o The delete() method is used to remove a portion of the string.
o The setCharAt() method is used to replace the character at the specified position.
o The final output should show the modified string.
Based on the given case, answer the following questions:
1. What is the purpose of the delete() method in the provided program?
a. It removes a character at a specified index b. It removes a range of characters from the string
c. It replaces characters at specified indices d. It converts the string to lowercase
2. What does the setCharAt() method do in this program?
a. Replaces a substring in the string b. Modifies the character at a specific index
c. Adds a character to the end of the string d. Converts the string to uppercase
3. What will be the output of the program after performing the delete and setCharAt operations?
a. "Java ming" b. "Java programming"
c. "jamming" d. "jamming programming"
F. Write the Java program for the following:
1. Write a program to store the string "Java Programming Language" in a variable.
The program should:
• Display the total number of characters in the string.
• Display the index position of the first occurrence of the character 'g'.
• Convert the string into uppercase letters.
The output should be as follows:
Length : 25
Index of g : 9
JAVA PROGRAMMING LANGUAGE
2. Write a program to store the string "Welcome To Computer World".
The program should:
• Convert the string into lowercase letters.
• Display the index of the character 'o' starting the search from index 10.
• Display the total length of the string.
Strings 319

