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