Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.37 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Problem_1 {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner Scanner = new Scanner(System.in);
  8.  
  9.         String key = Scanner.nextLine();
  10.  
  11.         String input = Scanner.nextLine();
  12.  
  13.         while (!"Generate".equals(input)) {
  14.             String[] tokens = input.split(">>>");
  15.             String command = tokens[0];
  16.  
  17.             switch (command) {
  18.                 case "Contains": {
  19.                     String wordForCheck = tokens[1];
  20.                     boolean searchWord = key.contains(wordForCheck);
  21.                     if (searchWord) {
  22.                         System.out.println(String.format("%s contains %s", key, wordForCheck));
  23.                     } else {
  24.                         System.out.println("Substring not found!");
  25.                     }
  26.                 }
  27.  
  28.                 break;
  29.                 case "Flip": {
  30.                     String secondCommand = tokens[1];
  31.                     int startIndex = Integer.parseInt(tokens[2]);
  32.                     int endIndex = Integer.parseInt(tokens[3]);
  33.                     StringBuilder sb = new StringBuilder(key);
  34.                     if ("Upper".equals(secondCommand)) {
  35.                         String upper = sb.substring(startIndex, endIndex);
  36.                         upper = upper.toUpperCase();
  37.                         sb = sb.replace(startIndex, endIndex, upper);
  38.                         key = sb.toString();
  39.  
  40.                     } else {
  41.                         String lower = sb.substring(startIndex, endIndex);
  42.                         lower = lower.toLowerCase();
  43.                         sb = sb.replace(startIndex, endIndex, lower);
  44.                         key = sb.toString();
  45.  
  46.                     }
  47.                     System.out.println(key);
  48.                 }
  49.                 break;
  50.                 case "Slice": {
  51.                     int startIndex = Integer.parseInt(tokens[1]);
  52.                     int endIndex = Integer.parseInt(tokens[2]);
  53.                     StringBuilder sb = new StringBuilder(key);
  54.                     sb = sb.replace(startIndex, endIndex, "");
  55.                     key=sb.toString();
  56.                     System.out.println(key);
  57.                 }
  58.                 break;
  59.             }
  60.             input = Scanner.nextLine();
  61.         }
  62.         System.out.println("Your activation key is: " + key);
  63.  
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement