Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String username = sc.nextLine();
- String input = sc.nextLine();
- while (!input.equals("Sign up")) {
- String[] inputArray = input.split("\\s+");
- switch (inputArray[0]) {
- case "Case":
- if (inputArray[1].equals("lower")) {
- username = username.toLowerCase();
- System.out.println(username);
- } else if (inputArray[1].equals("upper")) {
- username = username.toUpperCase();
- System.out.println(username);
- }
- break;
- case "Reverse":
- int startIndex = Integer.parseInt(inputArray[1]);
- int endIndex = Integer.parseInt(inputArray[2]) + 1;
- int length = username.length();
- if (startIndex >= 0 && length >= endIndex) {
- String substring = username.substring(startIndex, endIndex);
- System.out.println(new StringBuilder(substring).reverse().toString());
- }
- break;
- case "Cut":
- String substring = inputArray[1];
- if (username.contains(substring)) {
- username = username.replace(substring, "");
- System.out.println(username);
- } else {
- System.out.printf("The word %s doesn't contain %s.%n", username, substring);
- }
- break;
- case "Replace":
- char inputCharReplace = inputArray[1].charAt(0);
- if (username.contains(inputCharReplace + "")) {
- username = username.replaceAll(inputCharReplace + "", "*");
- System.out.println(username);
- }
- break;
- case "Check":
- char inputChar = inputArray[1].charAt(0);
- boolean contains = username.contains(inputChar + "");
- if (contains) {
- System.out.println("Valid");
- } else {
- System.out.printf("Your username must contain %s.%n", inputChar);
- }
- break;
- }
- input = sc.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement