Advertisement
SIRAKOV4444

Untitled

Apr 6th, 2020
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. public class lqlq {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String password= scanner.nextLine();
  10. String commands= scanner.nextLine();
  11. String newRawPassword="";
  12. while (!commands.equals("Done")){
  13. String[]input=commands.split("\\s+");
  14. String caseS=input[0];
  15.  
  16. switch (caseS){
  17. case"TakeOdd":
  18. for(int i=0;i<=password.length()-1;i++){
  19. if(i%2!=0){
  20. String currentChar=""+password.charAt(i);
  21. newRawPassword=newRawPassword+currentChar;
  22. }
  23. }
  24. System.out.println(String.format(newRawPassword));
  25. break;
  26. case"Cut":
  27. int index=Integer.parseInt(input[1]);
  28. int length=Integer.parseInt(input[2]);
  29. String subString=newRawPassword.substring(index,(index+length));
  30. newRawPassword=newRawPassword.replace(subString,"");
  31. System.out.println(String.format(newRawPassword));
  32. break;
  33. case"Substitute":
  34. String sString=input[1];
  35. String substitute=input[2];
  36. if (newRawPassword.contains(sString)) {
  37. while (newRawPassword.contains(sString)) {
  38. newRawPassword = newRawPassword.replace(sString, substitute);
  39. }
  40. System.out.println(String.format(newRawPassword));
  41. }else{
  42. System.out.println(String.format("Nothing to replace!"));
  43. }
  44. break;
  45. }
  46. commands= scanner.nextLine();
  47. }
  48. System.out.println(String.format("Your password is: %s",newRawPassword));
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement