Question: This is my code... import java.util.Scanner; public class TextMsgExpander { public static void main(String[] args) { //Declaring String variables String txtMsg,mesg,replaced ; //Scanner Object is
This is my code...
import java.util.Scanner; public class TextMsgExpander { public static void main(String[] args) { //Declaring String variables String txtMsg,mesg,replaced ; //Scanner Object is used to get the inputs entered by the user Scanner sc=new Scanner(System.in);
String BFF="best friend forever"; String IDK="I don't know"; String TMI="Too much information"; String LOL="Laughing out loud"; String IMHO="In my honest opinion"; String TTYL="talk to you later"; String JK="just kidding"; //Getting the inputs entered by the user. System.out.println("Enter text: "); txtMsg=sc.nextLine();
//Displaying the user entered Input String System.out.println("You entered: "+txtMsg+" "); // Check whether the entered string contains Particular string or not if(txtMsg.contains("BFF")) { txtMsg=txtMsg.replace("BFF",BFF); System.out.println("Replaced \"BFF\" with "+BFF); }
// Check whether the entered string contains Particular string or not if(txtMsg.contains("IDK")) { txtMsg=txtMsg.replace("IDK",IDK); System.out.println("Replaced \"IDK\" with \""+IDK+"\""); }
// Check whether the entered string contains Particular string or not if(txtMsg.contains("TMI")) { txtMsg=txtMsg.replace("TMI",TMI); System.out.println("Replaced \"TMI\" with \""+TMI+"\""); }
// Check whether the entered string contains Particular string or not if(txtMsg.contains("LOL")) { txtMsg=txtMsg.replace("LOL",LOL); System.out.println("Replaced \"LOL\" with \""+LOL+"\""); }
// Check whether the entered string contains Particular string or not if(txtMsg.contains("IMHO")) { txtMsg=txtMsg.replace("IMHO",IMHO); System.out.println("Replaced \"IMHO\" with \""+IMHO+"\""); }
// Check whether the entered string contains Particular string or not if(txtMsg.contains("TTYL")) { txtMsg=txtMsg.replace("TTYL",TTYL); System.out.println("Replaced \"TTYL\" with \""+TTYL+"\""); }
// Check whether the entered string contains Particular string or not if(txtMsg.contains("JK")) { txtMsg=txtMsg.replace("JK",JK); System.out.println("Replaced \"JK\" with \""+JK+"\""); } //Displaying the expanded form. System.out.println(" Expanded: "+txtMsg); } }
my output results are as follows and I need to add a . to the end of some lines and don't know how...

![void main(String[] args) { //Declaring String variables String txtMsg,mesg,replaced ; //Scanner Object](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f13eb0ead98_25666f13eb06be36.jpg)

2. Compare output IDK how that happened. TTYL. Input Enter text: You entered: IDK how that happened. TTYL . Your output Replaced "IDK" with "I don't know" Replaced "TTYL" with "talk to you later" Expanded: I don't know how that happened. talk to you later. Enter text: tered: IDK how that happened. TTYL. Expected output Rep laced "IDK"with "I don't know" Replaced "TTYL" with "talk to you later" Expanded: I don't know how that happened. talk to you later
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
