Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package finalExamPrep;
- import java.util.Scanner;
- public class StringManipulatorG1 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String text = scanner.nextLine();
- String input = scanner.nextLine();
- while (!input.equals("End")) {
- String[] token = input.split(" ");
- String command = token[0];
- switch (command) {
- case "Translate":
- char ch = token[1].charAt(0);
- char replacement = token[2].charAt(0);
- text = text.replace(ch, replacement);
- System.out.println(text);
- break;
- case "Includes":
- String string = token[1];
- if (text.contains(string)) {
- System.out.println("True");
- } else {
- System.out.println("False");
- }
- break;
- case "Start":
- String string1 = token[1];
- if (text.startsWith(string1)) {
- System.out.println("True");
- } else {
- System.out.println("False");
- }
- break;
- case "Lowercase":
- text = text.toLowerCase();
- System.out.println(text);
- break;
- case "FindIndex":
- int lastIndex = 0;
- char chr = token[1].charAt(0);
- for (int i = 0; i < text.length(); i++) {
- if (chr == text.charAt(i)) {
- lastIndex = i;
- }
- }
- System.out.println(lastIndex);
- break;
- case "Remove":
- int starting = Integer.parseInt(token[1]);
- int count = Integer.parseInt(token[2]);
- StringBuilder builder = new StringBuilder();
- builder.append(text);
- builder = builder.replace(starting, starting + count, "");
- text=builder.toString();
- System.out.println(text);
- break;
- }
- input = scanner.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement