Advertisement
petur_stoqnov

Untitled

Aug 14th, 2021
1,227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.61 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.         String username = sc.nextLine();
  10.         String input = sc.nextLine();
  11.  
  12.         while (!input.equals("Sign up")) {
  13.             String[] inputArray = input.split("\\s+");
  14.  
  15.             switch (inputArray[0]) {
  16.                 case "Case":
  17.                     if (inputArray[1].equals("lower")) {
  18.                         username = username.toLowerCase();
  19.                         System.out.println(username);
  20.                     } else if (inputArray[1].equals("upper")) {
  21.                         username = username.toUpperCase();
  22.                         System.out.println(username);
  23.                     }
  24.                     break;
  25.                 case "Reverse":
  26.                     int startIndex = Integer.parseInt(inputArray[1]);
  27.                     int endIndex = Integer.parseInt(inputArray[2]) + 1;
  28.                     int length = username.length();
  29.                     if (startIndex >= 0 && length >= endIndex) {
  30.                         String substring = username.substring(startIndex, endIndex);
  31.                         System.out.println(new StringBuilder(substring).reverse().toString());
  32.                     }
  33.                     break;
  34.                 case "Cut":
  35.                     String substring = inputArray[1];
  36.                     if (username.contains(substring)) {
  37.                         username = username.replace(substring, "");
  38.                         System.out.println(username);
  39.                     } else {
  40.                         System.out.printf("The word %s doesn't contain %s.%n", username, substring);
  41.                     }
  42.                     break;
  43.                 case "Replace":
  44.                     char inputCharReplace = inputArray[1].charAt(0);
  45.                     if (username.contains(inputCharReplace + "")) {
  46.                         username = username.replaceAll(inputCharReplace + "", "*");
  47.                         System.out.println(username);
  48.                     }
  49.                     break;
  50.                 case "Check":
  51.                     char inputChar = inputArray[1].charAt(0);
  52.                     boolean contains = username.contains(inputChar + "");
  53.                     if (contains) {
  54.                         System.out.println("Valid");
  55.                     } else {
  56.                         System.out.printf("Your username must contain %s.%n", inputChar);
  57.                     }
  58.                     break;
  59.             }
  60.  
  61.             input = sc.nextLine();
  62.         }
  63.  
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement