View the step-by-step solution to:

Question

Make sure to answer in this format


import java.util.Scanner;


public class

TextMsgExpander {

public static void main(String[] args) {



String textMsg;

String BFF="best friend forever";

String IDK="I don't know";

String JK="just kidding";

String TMI="too much information";

String TTYL="talk to you later";


System.out.println("Enter text: ");

Scanner scnr = new Scanner(System.in);

textMsg=scnr.nextLine();

System.out.println("You entered: "+textMsg);


//java indexOf function returns position of the string which you search

//it return -1 if not found


if(textMsg.indexOf("BFF")>=0)  

{

textMsg=textMsg.replace("BFF",BFF);

System.out.println("Replaced "BFF" with "+BFF);

}


if(textMsg.indexOf("IDK")>=0)

{

textMsg=textMsg.replace("IDK",IDK);

System.out.println("Replaced "IDK" with "+IDK);

}


if(textMsg.indexOf("JK")>=0)

{

textMsg=textMsg.replace("JK",JK);

System.out.println("Replaced "JK" with "+JK);

}


if(textMsg.indexOf("TMI")>=0)

{

textMsg=textMsg.replace("TMI",TMI);

System.out.println("Replaced "TMI" with "+TMI);

}


if(textMsg.indexOf("TTYL")>=0)

{

textMsg=textMsg.replace("TTYL",TTYL);

System.out.println("Replaced "TTYL" with "+TTYL);

}



System.out.println("Expanded: "+textMsg);

System.out.println("textMsg.indexOf: "+textMsg.indexOf("TTYL"));


}

}

Annotation 2020-02-11 162139.png

Annotation 2020-02-11 162139.png

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Let our 24/7 Computer Science tutors help you get unstuck! Ask your first question.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors