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