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