Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package FinalExam.O4;
- import java.util.Scanner;
- public class O1PasswordReset {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- StringBuilder input = new StringBuilder(scanner.nextLine());
- String command = scanner.nextLine();
- while (!"Done".equals(command)) {
- String[] type = command.split("\\s+");
- switch (type[0]) {
- case "TakeOdd":
- StringBuilder test = new StringBuilder();
- for (int i = 0; i < input.length(); i++) {
- if (i % 2 > 0) {
- test.append(input.charAt(i));
- }
- }
- input = new StringBuilder(test);
- System.out.println(input);
- break;
- case "Cut":
- int from = Integer.parseInt(type[1]);
- int to = Integer.parseInt(type[2]);
- input.delete(from, from + to);
- System.out.println(input);
- break;
- case "Substitute":
- if (input.toString().contains(type[1])) {
- input = new StringBuilder(input.toString().replace(type[1], type[2]));
- System.out.println(input);
- } else {
- System.out.println("Nothing to replace!");
- }
- break;
- }
- command = scanner.nextLine();
- }
- System.out.println("Your password is: " + input);
- }
- }
Add Comment
Please, Sign In to add comment