Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class first {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String text = scanner.nextLine();
- String command = scanner.nextLine();
- while (!"Done".equals(command)) {
- String[] tokens = command.split("\\s");
- switch (tokens[0]) {
- case "TakeOdd":
- StringBuilder sb = new StringBuilder();
- for (int i = 1; i < text.length(); i += 2) {
- sb.append(text.charAt(i));
- }
- text = sb.toString();
- System.out.println(text);
- break;
- case "Cut": {
- int index = Integer.parseInt(tokens[1]);
- int lenght = Integer.parseInt(tokens[2]);
- String sub = text.substring(index, index + lenght);
- StringBuilder builder = new StringBuilder();
- builder.append(text);
- builder.replace(builder.indexOf(sub), builder.indexOf(sub) + sub.length(), "");
- text = builder.toString();
- System.out.println(text);
- }
- break;
- case "Substitute":
- String old = tokens[1];
- String replecement = tokens[2];
- if (text.contains(old)) {
- text = text.replace(old, replecement);
- System.out.println(text);
- } else {
- System.out.println("Nothing to replace!");
- }
- break;
- }
- command = scanner.nextLine();
- }
- System.out.println(String.format("Your password is: %s", text));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement