Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class StringManipulator {
  4. public static void main(String[] args) {
  5.  
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. String string = scanner.nextLine();
  9. String command = scanner.nextLine();
  10.  
  11. while (!command.equals("Done")) {
  12.  
  13. String[] commandParts = command.split(" ");
  14. String commandType = commandParts[0];
  15.  
  16. switch (commandType) {
  17. case "Change":
  18. string = string.replace(commandParts[1], commandParts[2]);
  19. System.out.println(string);
  20. break;
  21. case "Includes":
  22. if (string.contains(commandParts[1])) {
  23. System.out.println("True");
  24. } else {
  25. System.out.println("False");
  26. }
  27. break;
  28. case "End":
  29. if (string.endsWith(commandParts[1])) {
  30. System.out.println("True");
  31. } else {
  32. System.out.println("False");
  33. }
  34. break;
  35. case "Uppercase":
  36. string = string.toUpperCase();
  37. System.out.println(string);
  38. break;
  39. case "FindIndex":
  40. int index = string.indexOf(commandParts[1]);
  41. System.out.println(index);
  42. break;
  43. case "Cut":
  44. String substring = commandParts[1];
  45. string = string.replace(substring, "");
  46. System.out.println(string);
  47. break;
  48. default:
  49. throw new IllegalStateException("Can't parse command" + command + "(" + commandType + ")");
  50. }
  51.  
  52. command = scanner.nextLine();
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement