Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TaskOne {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String easter = scan.nextLine();
- String command = scan.nextLine(); //команда или "Done"
- while (!command.equals("Easter")) {
- //"Replace {currentChar} {newChar}"
- if (command.contains("Replace")) {
- String currentSymbol = command.split("\\s+")[1];
- String newSymbol = command.split("\\s+")[2];
- String newEaster=easter.replaceAll(currentSymbol,(newSymbol));
- System.out.println(newEaster);
- } else if(command.contains("Remove")){
- //Remove substring
- String substring =command.split("\\s+")[1];
- String rem =easter.replace(substring,"");
- System.out.println(rem);
- /*
- StringBuilder sb =new StringBuilder();
- sb.append(easter);
- sb.delete(1,sb.indexOf(substring)+1);
- String result = sb.toString();
- System.out.println(result);
- */
- }else if(command.contains("Includes")){
- //Includes string
- String str =command.split("\\s+")[1];
- if(command.contains(str)){
- System.out.println("True");
- }else{
- System.out.println("False");
- }
- }else if(command.contains("Change")){
- //Change Lower/Upper - i I
- String changeStr =easter.replaceAll(easter.toLowerCase(),easter.toUpperCase());
- System.out.println(changeStr);
- }else if(command.contains("Reverse")){
- //Reverse startInd endInd
- int startInd =Integer.parseInt(command.split("\\s+")[1]);
- int endInd =Integer.parseInt(command.split("\\s+")[2]);
- if(startInd>=0 && endInd>0 && startInd <=easter.length()-1 && endInd <=easter.length()-1){
- StringBuilder sb2 =new StringBuilder();
- sb2.append(easter);
- sb2.reverse();
- String revSb2=sb2.toString();
- System.out.println(revSb2);
- }
- }
- command = scan.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement