Advertisement
Guest User

Untitled

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