4.31.1: LAB*: Program: Text messag
unknown
javascript
3 years ago
1.7 kB
9
Indexable
import java.util.Scanner;
public class TextMsgExpander {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
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:");
String userInput = scnr.nextLine();
if (!userInput.isEmpty()) {
System.out.println("You entered: " + userInput + "\n"); // \n creates a new line after userInput.
}
if (userInput.contains("BFF")) {
userInput = userInput.replace("BFF", BFF);
System.out.println("Replaced \"BFF\" with \"best friend forever\"." + "\n");
}
if (userInput.contains("IDK")) {
userInput = userInput.replace("IDK", IDK);
System.out.println("Replaced \"IDK\" with \"I don't know\".");
}
if (userInput.contains("JK")) {
userInput = userInput.replace("JK", JK);
System.out.println("Replaced \"JK\" with \"just kidding\"." + "\n");
}
if (userInput.contains("TMI")) {
userInput = userInput.replace("TMI", TMI);
System.out.println("Replaced \"TMI\" with \"too much information\"." + "\n");
}
if (userInput.contains("TTYL")) {
userInput = userInput.replace("TTYL", TTYL);
System.out.println("Replaced \"TTYL\" with \"talk to you later\"." + "\n");
}
System.out.println("Expanded: " + userInput);
scnr.close();
}
}
Editor is loading...