Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String string = scan.nextLine();
- String input = scan.nextLine();
- while (!"For Azeroth".equals(input)) {
- String[] tokens = input.split("\\s+");
- String command = tokens[0];
- switch (command) {
- case "GladiatorStance":
- string = string.toUpperCase();
- System.out.println(string);
- break;
- case "DefensiveStance":
- string = string.toLowerCase();
- System.out.println(string);
- break;
- case "Dispel":
- int index = Integer.parseInt(tokens[1]);
- char letter = tokens[2].charAt(0);
- if (index >= 0 && index < string.length()) {
- StringBuilder sb = new StringBuilder(string);
- sb.setCharAt(index, letter);
- string = sb.toString();
- System.out.println("Success!");
- } else {
- System.out.println("Dispel too weak.");
- }
- break;
- case "Target":
- if ("Change".equals(tokens[1])) {
- String firstSubstr = tokens[2];
- String secondsSubstr = tokens[3];
- string = string.replace(firstSubstr, secondsSubstr);
- System.out.println(string);
- } else if ("Remove".equals(tokens[1])) {
- String substring = tokens[2];
- string = string.replace(substring, "");
- System.out.println(string);
- } else {
- System.out.println("Command doesn't exist!");
- }
- break;
- default:
- System.out.println("Command doesn't exist!");
- }
- input = scan.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement