Advertisement
CR7CR7

taskexam

Nov 15th, 2022
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.regex.Pattern;
  3.  
  4. public class ExamTask___SecretChat {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         String input = scanner.nextLine();
  9.  
  10.         String[] task = scanner.nextLine().split(":\\|:");
  11.  
  12.         while (!task[0].equals("Reveal")) {
  13.  
  14.             switch (task[0]) {
  15.             case ("ChangeAll"):
  16.                 input = input.replace(task[1], task[2]);
  17.                 System.out.println(input);
  18.                 break;
  19.             case ("InsertSpace"):
  20.                 int spaceNum = Integer.parseInt(task[1]);
  21.                 input = input.substring(0, spaceNum) + " " + input.substring(spaceNum, input.length());
  22.                 System.out.println(input);
  23.                 break;
  24.             case ("Reverse"):
  25.                 String forCheck = task[1];
  26.                 if (input.contains(forCheck)) {
  27.                     String forReplays = new StringBuilder(forCheck).reverse().toString();
  28.                     input = input.replaceFirst(Pattern.quote(forCheck), "") + forReplays;
  29.                     System.out.println(input);
  30.                 } else {
  31.                     System.out.println("error");
  32.                 }
  33.                 break;
  34.             }
  35.             task = scanner.nextLine().split(":\\|:");
  36.         }
  37.         System.out.printf("You have a new text message: %s", input);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement