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