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