Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package FinalExam.O5;
- import java.util.Scanner;
- public class O1ActivationKey {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- StringBuilder key = new StringBuilder(scanner.nextLine());
- String input;
- while (!"Generate".equals(input = scanner.nextLine())) {
- String[] command = input.split(">>>");
- switch (command[0]){
- case"Contains":
- if (key.toString().contains(command[1])) {
- System.out.printf("%s contains %s%n", key, command[1]);
- } else {
- System.out.println("Substring not found!");
- }
- break;
- case"Slice":
- key.delete(Integer.parseInt(command[1]), Integer.parseInt(command[2]));
- System.out.println(key);
- break;
- case"Flip":
- if (command[1].equals("Upper")) {
- key.replace(Integer.parseInt(command[2]), Integer.parseInt(command[3]),
- key.substring(Integer.parseInt(command[2]), Integer.parseInt(command[3])).toUpperCase());
- } else {
- key.replace(Integer.parseInt(command[2]), Integer.parseInt(command[3]),
- key.substring(Integer.parseInt(command[2]), Integer.parseInt(command[3])).toLowerCase());
- }
- System.out.println(key);
- break;
- }
- }
- System.out.println("Your activation key is: " + key);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment