Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class Password {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         String rawPass = "";
  8.         String password = scanner.nextLine();
  9.         String command = scanner.nextLine();
  10.  
  11.         while (!command.contains("Done")){
  12.             String[] commandParts =command.split(" ");
  13.  
  14.             if (commandParts[0].equals("TakeOdd")){
  15.                 for (int i = 0; i < password.length(); i++) {
  16.                     if(i %2 == 1){
  17.                         String parts = String.valueOf(password.charAt(i));
  18.                         rawPass += parts;
  19.  
  20.                     }
  21.                 }
  22.                 System.out.println(rawPass);
  23.  
  24.             } if (commandParts[0].equals("Cut")){
  25.                 int startIndex = Integer.parseInt(commandParts[1]);
  26.                 int length = Integer.parseInt(commandParts[2]);
  27.                 String firstPart=rawPass.substring(0,startIndex);
  28.                 String secondPart = rawPass.substring(startIndex+length,rawPass.length());
  29.                 rawPass = firstPart+secondPart;
  30.                 System.out.println(rawPass);
  31.  
  32.  
  33.             } if (commandParts[0].equals("Substitute")){
  34.                     if (rawPass.contains(commandParts[1])){
  35.  
  36.                        rawPass = rawPass.replaceAll(commandParts[1],commandParts[2]);
  37.                         System.out.println(rawPass);
  38.  
  39.                     }else {
  40.                         System.out.println("Nothing to replace!");
  41.                     }
  42.  
  43.             }
  44.  
  45.             command=scanner.nextLine();
  46.             if (command.contains("Done")){
  47.                 System.out.println("Your password is: "+rawPass);
  48.             }
  49.         }
  50.  
  51.  
  52.  
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement