Question: Code from Exercise 3: package osu.cse1223; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Lab13c { /** * delete a character from String based on

 Code from Exercise 3: package osu.cse1223; import java.io.BufferedReader; import java.io.IOException; import

Code from Exercise 3:

package osu.cse1223; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Lab13c { /** * delete a character from String based on char position. * * @param input String to delete specific char based on its position * @return the input String after delete a char. */ public static String removeCharacterFromString(String input, int n) { StringBuilder result = new StringBuilder(); for (int i = 0; i

do{ System.out.println("Enter a position to delete (-1 to end) : "); n = Integer.parseInt(buf.readLine()); if(n >= 0){ s = removeCharacterFromString(s, n); System.out.println("Current String : "+s); } else{ break; }

}while(!s.isEmpty()); n=0; System.out.println("Final String : "+s); } else{ break; } } System.out.println("Good Bye!"); } }

Exercise 4 If you have time, create a copy of your solution for Exercise 3 and name it Lab13d.java in the same ClosedLab13 folder. For this exercise, modify your program to remove substrings of the original string instead of positions. As a hint towards how to go about doing this, take a look at the StringBuilder methods indexOf and delete. As in Exercise 3, you can write methods to do this or do it all in the main method for this closed lab question. A sample transcript appears below: Enter a string (empty to quit): Hello World! Enter a substring to delete (empty to endorld Current string: Hello W! Enter a position to delete (empty to end) lo Current string: Hel W! Enter a position to delete (empty to end): He Current string: 1 W! Enter a position to delete (empty to end)! Current string: 1 W Enter a position to delete (empty to end): Final String: l W Enter a string (empty to quit)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!