Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package examPrepFinal;
- import java.util.Scanner;
- public class P01ActivationKeys {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String activationKey = scanner.nextLine();
- String inputLine = scanner.nextLine();
- while (!inputLine.equals("Generate")) {
- String[] tokens = inputLine.split(">>>");
- String command = tokens[0];
- switch (command) {
- case "Contains":
- String substring = tokens[1];
- if (activationKey.contains(substring)) {
- System.out.printf("%s contains %s%n", activationKey, substring);
- } else {
- System.out.println("Substring not found!");
- }
- break;
- case "Flip":
- String criteria = tokens[1];
- int startIndex = Integer.parseInt(tokens[2]);
- int endIndex = Integer.parseInt(tokens[3]);
- String substringToReplace = activationKey.substring(startIndex, endIndex);
- if (criteria.equals("Upper")) {
- activationKey = activationKey.replace(substringToReplace,
- substringToReplace.toUpperCase());
- } else {
- activationKey = activationKey.replace(substringToReplace,
- substringToReplace.toLowerCase());
- }
- System.out.println(activationKey);
- break;
- case "Slice":
- int start = Integer.parseInt(tokens[1]);
- int end = Integer.parseInt(tokens[2]);
- String substringToRemove = activationKey.substring(start, end);
- activationKey = activationKey.replace(substringToRemove, "");
- System.out.println(activationKey);
- break;
- }
- inputLine = scanner.nextLine();
- }
- System.out.printf("Your activation key is: %s%n", activationKey);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement