Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package FinalExam.O3;
- import java.util.Scanner;
- public class O1SecretChat {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- StringBuilder input = new StringBuilder(scanner.nextLine());
- String command = scanner.nextLine();
- while (!command.equals("Reveal")) {
- String[] type = command.split(":\\|:");
- switch (type[0]) {
- case "ChangeAll":
- input = new StringBuilder(input.toString().replace(type[1], type[2]));
- System.out.println(input);
- break;
- case "Reverse":
- if (input.toString().contains(type[1])) {
- input.delete(input.indexOf(type[1]), input.indexOf(type[1]) + type[1].length())
- .append(new StringBuilder(type[1]).reverse());
- System.out.println(input);
- } else {
- System.out.println("error");
- }
- break;
- case "InsertSpace":
- input.insert(Integer.parseInt(type[1]), " ");
- System.out.println(input);
- break;
- }
- command = scanner.nextLine();
- }
- System.out.println("You have a new text message: " + input);
- }
- }
Add Comment
Please, Sign In to add comment