Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class StringManipulator {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String string = scanner.nextLine();
- String command = scanner.nextLine();
- while (!command.equals("Done")) {
- String[] commandParts = command.split(" ");
- String commandType = commandParts[0];
- switch (commandType) {
- case "Change":
- string = string.replace(commandParts[1], commandParts[2]);
- System.out.println(string);
- break;
- case "Includes":
- if (string.contains(commandParts[1])) {
- System.out.println("True");
- } else {
- System.out.println("False");
- }
- break;
- case "End":
- if (string.endsWith(commandParts[1])) {
- System.out.println("True");
- } else {
- System.out.println("False");
- }
- break;
- case "Uppercase":
- string = string.toUpperCase();
- System.out.println(string);
- break;
- case "FindIndex":
- int index = string.indexOf(commandParts[1]);
- System.out.println(index);
- break;
- case "Cut":
- String substring = commandParts[1];
- string = string.replace(substring, "");
- System.out.println(string);
- break;
- default:
- throw new IllegalStateException("Can't parse command" + command + "(" + commandType + ")");
- }
- command = scanner.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement