Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class StringManipulator2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String message = scanner.nextLine();
- String[] command = scanner.nextLine().split("\\s+");
- while (!command[0].equals("Done")) {
- String word = command[0];
- switch (word) {
- case "Change":
- String existedChar = command[1];
- String replacement = command[2];
- message = message.replace(existedChar, replacement);
- System.out.println(message);
- break;
- case "Includes":
- String part = command[1];
- if (message.contains(part)) {
- System.out.println("True");
- } else {
- System.out.println("False");
- }
- break;
- case "End":
- String lastPart = command[1];
- if (message.endsWith(lastPart)) {
- System.out.println("True");
- } else {
- System.out.println("False");
- }
- break;
- case "Uppercase":
- message = message.toUpperCase();
- System.out.println(message);
- break;
- case "FindIndex":
- String symbol = command[1];
- int index = message.indexOf(symbol);
- System.out.println(index);
- break;
- case "Cut":
- int startIndex = Integer.parseInt(command[1]);
- int endIndex = Integer.parseInt(command[2]);
- message = message.substring(startIndex, startIndex + endIndex);
- System.out.println(message);
- break;
- }
- command = scanner.nextLine().split("\\s+");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement