Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is a statement of work (SOW)? What purpose does it serve?

Answered: 1 week ago

Question

3. Avoid making mistakes when reaching our goals

Answered: 1 week ago

Question

Find y'. y= |x + X (x) (x) X 1 02x+ 2x 1 O 2x + 1/3 Ex 2x +

Answered: 1 week ago

Question

Which form of proof do you find most persuasive? Why?

Answered: 1 week ago