Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TextMsgDecoder {
  4. public static void main(String[] args) {
  5.  
  6. // define variables
  7. Scanner scnr = new Scanner(System.in);
  8. String message;
  9.  
  10. // ask user for input
  11. System.out.println("Enter text:");
  12. message = scnr.nextLine();
  13.  
  14. // display message
  15. System.out.println("You entered: " + message);
  16.  
  17. // test message (copy paste it):
  18. // IDK if I'll go. It's my BFF's birthday.
  19.  
  20. // now we need to search the message for supported abbreviations
  21. // indexOf gives an index if matching string is found, else it gives -1
  22. // we don't care about the actual index number, but we do care to see
  23. // if it gives us -1 or not, based on that info, we print what it finds
  24. if (message.indexOf("BFF") != -1) {
  25. System.out.println("BFF: best friend forever");
  26. }
  27.  
  28. // now we just follow the same format for the other ones and done
  29. if (message.indexOf("IDK") != -1) {
  30. System.out.println("IDK: I don't know");
  31. }
  32. if (message.indexOf("JK") != -1) {
  33. System.out.println("JK: just kidding");
  34. }
  35. if (message.indexOf("TMI") != -1) {
  36. System.out.println("TMI: too much information");
  37. }
  38. if (message.indexOf("TTYL") != -1) {
  39. System.out.println("TTYL: talk to you later");
  40. }
  41.  
  42. scnr.close(); // always close the scanner
  43.  
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement