Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class practice{
- public static void main(String[]args){
- Scanner sc=new Scanner(System.in);
- String key=sc.nextLine();
- String instructions=sc.nextLine();
- while (!instructions.equals("Generate")){
- String[]commands=instructions.split(">>>");
- String cases=commands[0];
- switch (cases){
- case"Contains":
- String subString=commands[1];
- if(key.contains(subString)){
- System.out.println(String.format("%s contains %s.",key,subString));
- }else{
- System.out.println(String.format("Substring not found!"));
- }
- break;
- case"Flip":
- String upperLower=commands[1];
- int startIndex=Integer.parseInt(commands[2]);
- int endIndex=Integer.parseInt(commands[3]);
- if(startIndex>=0 && startIndex<key.length() && endIndex>=0 && endIndex<key.length()) {
- if (upperLower.equals("Upper")) {
- String subS = key.substring(startIndex, endIndex);//??????
- key = key.replace(subS, subS.toUpperCase());
- } else {
- String subSS = key.substring(startIndex, endIndex);//??????
- key = key.replace(subSS, subSS.toLowerCase());
- }
- }
- System.out.println(String.format(key));
- break;
- case"Slice":
- int startX=Integer.parseInt(commands[1]);
- int endX=Integer.parseInt(commands[2]);
- if(startX>=0 && startX<=key.length()-1 && endX>=0 && endX<=key.length()-1) {
- String subSSS = key.substring(startX, endX);
- key = key.replace(subSSS, "");
- }
- System.out.println(String.format(key));
- break;
- default:
- throw new IllegalStateException("wrong input!!!");
- }
- instructions=sc.nextLine();
- }
- System.out.println(String.format("Your activation key is: %s",key));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement