SHARE
TWEET

Untitled

a guest Jan 24th, 2020 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.LinkedHashMap;
  2. import java.util.Map;
  3. import java.util.Scanner;
  4.  
  5. public class FixEmails {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String name = scanner.nextLine();
  10.  
  11.         Map<String, String> contacts = new LinkedHashMap<>();
  12.  
  13.         while (!name.equals("stop")) {
  14.             String email = scanner.nextLine();
  15.  
  16.             if (!contacts.containsKey(name) && checkIsValidEmail(email)){
  17.                 contacts.put(name,email);
  18.             }
  19.             name = scanner.nextLine();
  20.         }
  21.         contacts.forEach((key, value) -> System.out.println(key + " -> " + value));
  22.  
  23.     }
  24.  
  25.     private static boolean checkIsValidEmail(String email) {
  26.         String domain = email.substring(email.lastIndexOf(".") + 1);
  27.  
  28.         return !(domain.equals("us") || domain.equals("uk") || domain.equals("com"));
  29.     }
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top