Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String text = scanner.nextLine();////Thi5 I5 MY 5trING!//
- String line = scanner.nextLine();//Translate 5 s
- while (!line.equals("End")) {
- String[] tokens = line.split(" +");
- String command = tokens[0];
- if (command.equals("Translate")) {
- char charToReplace = tokens[1].charAt(0);
- char replacer = tokens[2].charAt(0);
- for (int i = 0; i < line.length(); i++) {
- char currentChar = line.charAt(i);
- if (currentChar == charToReplace) {
- text = text.replace(charToReplace, replacer);
- }
- }
- System.out.println(text);
- } else if (command.equals("Includes")) {
- String toCheck = tokens[1];
- if (text.contains(toCheck)) {
- System.out.println("True");
- } else {
- System.out.println("False");
- }
- } else if (command.equals("Start")) {
- String[] textAsArray = text.split(" +");
- String currentStart = textAsArray[0];
- String startToChck = tokens[1];
- if (currentStart.equals(startToChck)) {
- System.out.println("True");
- } else {
- System.out.println("False");
- }
- } else if (command.equals("Lowercase")) {
- text = text.toLowerCase();
- System.out.println(text);
- } else if (command.equals("FindIndex")) {
- char index = tokens[1].charAt(0);
- int lastIndexOf = (text.lastIndexOf(index));
- System.out.println(lastIndexOf);
- } else if (command.equals("Remove")) {
- int startIndex = Integer.parseInt(tokens[1]);
- int endIndex = Integer.parseInt(tokens[2]);
- if(startIndex>=0&&endIndex<text.length()){// if (index >= 0 && index < numbers.size())
- String toRemove = text.substring(startIndex, endIndex);
- text = text.replace(toRemove, "");
- System.out.println(text);
- }
- }
- line = scanner.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement