Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Problem_1 {
- public static void main(String[] args) {
- Scanner Scanner = new Scanner(System.in);
- String key = Scanner.nextLine();
- String input = Scanner.nextLine();
- while (!"Generate".equals(input)) {
- String[] tokens = input.split(">>>");
- String command = tokens[0];
- switch (command) {
- case "Contains": {
- String wordForCheck = tokens[1];
- boolean searchWord = key.contains(wordForCheck);
- if (searchWord) {
- System.out.println(String.format("%s contains %s", key, wordForCheck));
- } else {
- System.out.println("Substring not found!");
- }
- }
- break;
- case "Flip": {
- String secondCommand = tokens[1];
- int startIndex = Integer.parseInt(tokens[2]);
- int endIndex = Integer.parseInt(tokens[3]);
- StringBuilder sb = new StringBuilder(key);
- if ("Upper".equals(secondCommand)) {
- String upper = sb.substring(startIndex, endIndex);
- upper = upper.toUpperCase();
- sb = sb.replace(startIndex, endIndex, upper);
- key = sb.toString();
- } else {
- String lower = sb.substring(startIndex, endIndex);
- lower = lower.toLowerCase();
- sb = sb.replace(startIndex, endIndex, lower);
- key = sb.toString();
- }
- System.out.println(key);
- }
- break;
- case "Slice": {
- int startIndex = Integer.parseInt(tokens[1]);
- int endIndex = Integer.parseInt(tokens[2]);
- StringBuilder sb = new StringBuilder(key);
- sb = sb.replace(startIndex, endIndex, "");
- key=sb.toString();
- System.out.println(key);
- }
- break;
- }
- input = Scanner.nextLine();
- }
- System.out.println("Your activation key is: " + key);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement