Question: Java Write a program that asks the user for some text and then it replaces 2 pieces of it (substrings). Hint: The special case when

Java

Write a program that asks the user for some text and then it replaces 2 pieces of it (substrings). Hint: The special case when one part to be substituted is at the begining does NOT need any special code. Whatever works for text in the middle, works for that as well. Remembre that you cannot 'substitute' in a string. You have to build a new string with the pieces needed form the old strings and the new pieces. Hint: Solve this problem by first 'substituting' the first piece, and then, in that new text, substitute the second piece. E.g. for the sample run 1 below the final text was produced following these steps: start with string: Wait. where is the car? produce a new string that has goes instead of is: Wait. where goes the car? using the last text, produce another one that has !!!!!!!!! insteda of . : Wait!!!!!!!!! where goes the car? you now have the final text. You can print it. Suggestion: Since you do not need to reprint the original text from the user, you can save all the new texts you produce in that same variable. (It is also ok to use new variable names.)

Sample run 1 (italic font shows user input): Enter the text: Wait. where is the car? Enter existing word 1: is Enter new word 1: goes Enter existing word 2: . Enter new word 2: !!!!!!!!! The new text is: Wait!!!!!!!!! where goes the car? Sample run 2: Enter the text: cats dogs house farm 36521 hdj Enter existing word 1: cats Enter new word 1: h Enter existing word 2: ar Enter new word 2: MMMM The new text is: h dogs house fMMMMm 36521 hdj 

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!