Question: Description: Once again, allow the user to first enter a main String. Next, allow them to also input two separate words: (1) the word they
Description: Once again, allow the user to first enter a main String. Next, allow them to also input two separate words: (1) the word they would like to be replaced, and (2) the word that will replace the first. Then locate all the occurrences of the first word in the main String, and replace all of them with the second word. If the user inputs a String (for the first word) that is not found in the main String, make sure to output a message stating that the word was not found.
There are two parts to this program. In Part 1, complete the find and replace code using a String method found from the Java API. You should be able to do this in one line of code. In Part 2, complete the find and replace code a second time without using the replace() String method. You will need to figure out how to do this with only loops, and without the Make sure to also have an output statement labelling each part, as shown in the example below. Below is the input and the output we expect from your program. This is to help you know if you are on the right track. Example input : Cows go moo moo moo moo, not meow. moo burp
Example output:
Enter a String: [String] Enter Word 1 (to be replaced):
[String] Enter Word 2 (that replaces Word 1): [String]
Part 1 New String: Cows go burp burp burp burp, not meow.
Part 2 New String: Cows go burp burp burp burp, not meow.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
