Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ActivationKeys {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String input = scanner.nextLine();
  8.  
  9.         while (true) {
  10.             String[] commands = scanner.nextLine().split(">>>");
  11.             if (commands[0].equals("Generate")) {
  12.                 break;
  13.             }
  14.             switch (commands[0]) {
  15.                 case "Contains":
  16.                     String substring = commands[1];
  17.                     if (input.contains(substring)) {
  18.                         System.out.println(String.format("%s contains %s", input, substring));
  19.                     } else {
  20.                         System.out.println("Substring not found!");
  21.                     }
  22.                     break;
  23.                 case "Flip":
  24.                     int startIndex = Integer.parseInt(commands[2]);
  25.                     int endIndex = Integer.parseInt(commands[3]);
  26.                     if (commands[1].equals("Upper")) {
  27.                         String inp1 = input.substring(startIndex, endIndex).toUpperCase();
  28.                         String inp2 = input.substring(0, startIndex);
  29.                         String inp3 = input.substring(endIndex, input.length());
  30.                         input = inp2 + inp1 + inp3;
  31.                         System.out.println(input);
  32.                     } else if (commands[1].equals("Lower")) {
  33.                         String inp1 = input.substring(startIndex, endIndex).toLowerCase();
  34.                         String inp2 = input.substring(0, startIndex);
  35.                         String inp3 = input.substring(endIndex, input.length());
  36.                         input = inp2 + inp1 + inp3;
  37.                         System.out.println(input);
  38.                     }
  39.                     break;
  40.                 case "Slice":
  41.                     int startInd = Integer.parseInt(commands[1]);
  42.                     int endInd = Integer.parseInt(commands[2]);
  43.                     input = input.substring(0, startInd) + input.substring(endInd, input.length());
  44.                     System.out.println(input);
  45.                     break;
  46.                 default:
  47.                     break;
  48.             }
  49.         }
  50.         System.out.println(String.format("Your activation key is: %s", input));
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement