Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class EmailValidator {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String email = scanner.nextLine();
- List<String> input = Arrays.stream(email.split("")).collect(Collectors.toList());
- while (true){
- String[] cmd = scanner.nextLine().split(" ");
- if (cmd[0].equals("Complete")){
- break;
- }
- if (cmd[0].equals("Make")){
- if (cmd[1].equals("Upper")){
- System.out.println(email.toUpperCase());
- for (int i = 0; i <input.size() ; i++) {
- String symbol = input.get(i);
- input.set(i,symbol.toUpperCase());
- }
- }
- else if (cmd[1].equals("Lower")){
- System.out.println(email.toLowerCase());
- for (int i = 0; i <input.size() ; i++) {
- String symbol = input.get(i);
- input.set(i,symbol.toLowerCase());
- }
- }
- }
- else if (cmd[0].equals("GetDomain")){
- int count = Integer.parseInt(cmd[1]);
- System.out.println(input.subList((input.size()-count),input.size()).toString()
- .replace("[","")
- .replace("]","")
- .replace(",","")
- .replace(" ",""));
- }
- else if (cmd[0].equals("GetUsername")){
- int index = input.indexOf("@");
- if (index>=0) {
- System.out.println(email.substring(0,index));
- }
- else {
- System.out.printf("The email %s doesn't contain the @ symbol.",email);
- System.out.println();
- }
- }
- else if (cmd[0].equals("Replace")){
- for (int i = 0; i <input.size() ; i++) {
- if (input.get(i).equals(cmd[1])){
- input.set(i,"-");
- }
- email = input.toString()
- .replace("[","")
- .replace("]","")
- .replace(",","")
- .replace(" ","");
- }
- System.out.println(email);
- }
- else if (cmd[0].equals("Encrypt")){
- for (String s : input) {
- System.out.print(((int) s.charAt(0))+" ");
- }
- System.out.println();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement