Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TextMsgDecoder {
- public static void main(String[] args) {
- // define variables
- Scanner scnr = new Scanner(System.in);
- String message;
- // ask user for input
- System.out.println("Enter text:");
- message = scnr.nextLine();
- // display message
- System.out.println("You entered: " + message);
- // test message (copy paste it):
- // IDK if I'll go. It's my BFF's birthday.
- // now we need to search the message for supported abbreviations
- // indexOf gives an index if matching string is found, else it gives -1
- // we don't care about the actual index number, but we do care to see
- // if it gives us -1 or not, based on that info, we print what it finds
- if (message.indexOf("BFF") != -1) {
- System.out.println("BFF: best friend forever");
- }
- // now we just follow the same format for the other ones and done
- if (message.indexOf("IDK") != -1) {
- System.out.println("IDK: I don't know");
- }
- if (message.indexOf("JK") != -1) {
- System.out.println("JK: just kidding");
- }
- if (message.indexOf("TMI") != -1) {
- System.out.println("TMI: too much information");
- }
- if (message.indexOf("TTYL") != -1) {
- System.out.println("TTYL: talk to you later");
- }
- scnr.close(); // always close the scanner
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement