Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company.softuni;
- import java.util.Scanner;
- public class Main2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String password = scanner.nextLine();
- String command = scanner.nextLine();
- while (!command.equals("Done")) {
- String[] tokens = command.split("\\s+");
- String commandName = tokens[0];
- switch (commandName) {
- case "TakeOdd":
- // Takes only the characters at odd indices and concatenates them together to obtain the new raw password and then prints it.
- StringBuilder newPass = new StringBuilder();
- for (int i = 0; i < password.length(); i++) {
- if (i % 2 == 1) {
- newPass.append(password.charAt(i));
- }
- }
- password = newPass.toString();
- System.out.println(password);
- break;
- case "Cut":
- int index = Integer.parseInt(tokens[1]);
- int length = Integer.parseInt(tokens[2]);
- String substr = password.substring(index, index + length);
- password = password.replace(substr, "");
- System.out.println(password);
- break;
- case "Substitute":
- String symbol = tokens[1];
- String replacement = tokens[2];
- if (password.contains(symbol)) {
- password = password.replace(symbol, replacement);
- System.out.println(password);
- } else {
- System.out.println("Nothing to replace!");
- }
- break;
- }
- command = scanner.nextLine();
- }
- System.out.printf("Your password is: %s", password);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement