Advertisement
SIRAKOV4444

Untitled

Apr 6th, 2020
1,029
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class practice {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6.  
  7. String key = sc.nextLine();
  8. String instructions = sc.nextLine();
  9. while (!instructions.equals("Generate")) {
  10. String[] commands = instructions.split(">>>");
  11. String cases = commands[0];
  12. switch (cases) {
  13. case "Contains":
  14. String subString = commands[1];
  15. if (key.contains(subString)) {
  16. System.out.println(String.format("%s contains %s.", key, subString));
  17. } else {
  18. System.out.println(String.format("Substring not found!"));
  19. }
  20. break;
  21. case "Flip"://StringBuilder
  22. String upperLower = commands[1];
  23. int startIndex = Integer.parseInt(commands[2]);
  24. int endIndex = Integer.parseInt(commands[3]);
  25. String toChanges = key.substring(startIndex, endIndex);
  26. if (upperLower.equals("Upper")) {
  27. toChanges=toChanges.toUpperCase();
  28. StringBuilder sb = new StringBuilder();
  29. sb.append(key);
  30. sb.replace(startIndex, endIndex, (toChanges));
  31. key = sb.toString();
  32. } else {
  33. toChanges=toChanges.toLowerCase();
  34. StringBuilder sb = new StringBuilder();
  35. sb.append(key);
  36. sb.replace(startIndex, endIndex, (toChanges));
  37. key = sb.toString();
  38.  
  39. }
  40. System.out.println(key);
  41. break;
  42. case "Slice"://StringBuilder
  43. int startX = Integer.parseInt(commands[1]);
  44. int endX = Integer.parseInt(commands[2]);
  45. StringBuilder deleter = new StringBuilder();
  46. deleter.append(key);
  47. deleter.replace(startX, endX, "");
  48. key=deleter.toString();
  49.  
  50. System.out.println(key);
  51. break;
  52. default:
  53. throw new IllegalStateException("wrong input!!!");
  54. }
  55. instructions = sc.nextLine();
  56. }
  57. System.out.println(String.format("Your activation key is: %s", key));
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement