Advertisement
svephoto

String Manipulator - Group 2

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