Advertisement
SIRAKOV4444

Untitled

Apr 6th, 2020
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 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":
  22. String upperLower=commands[1];
  23. int startIndex=Integer.parseInt(commands[2]);
  24. int endIndex=Integer.parseInt(commands[3]);
  25.  
  26. if(startIndex>=0 && startIndex<key.length() && endIndex>=0 && endIndex<key.length()) {
  27. if (upperLower.equals("Upper")) {
  28. String subS = key.substring(startIndex, endIndex);//??????
  29.  
  30. key = key.replace(subS, subS.toUpperCase());
  31. } else {
  32. String subSS = key.substring(startIndex, endIndex);//??????
  33.  
  34. key = key.replace(subSS, subSS.toLowerCase());
  35. }
  36. }
  37. System.out.println(String.format(key));
  38. break;
  39. case"Slice":
  40. int startX=Integer.parseInt(commands[1]);
  41. int endX=Integer.parseInt(commands[2]);
  42.  
  43. if(startX>=0 && startX<=key.length()-1 && endX>=0 && endX<=key.length()-1) {
  44. String subSSS = key.substring(startX, endX);
  45. key = key.replace(subSSS, "");
  46. }
  47. System.out.println(String.format(key));
  48. break;
  49. default:
  50. throw new IllegalStateException("wrong input!!!");
  51. }
  52. instructions=sc.nextLine();
  53. }
  54. System.out.println(String.format("Your activation key is: %s",key));
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement