Advertisement
desislava_topuzakova

07. Fix Emails

Jan 18th, 2022
865
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package SetsAndMapAdvanced_Exercise;
  2.  
  3. import java.util.HashMap;
  4. import java.util.LinkedHashMap;
  5. import java.util.Map;
  6. import java.util.Scanner;
  7.  
  8. public class FixEmails_07 {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.         //име на човек -> имейл
  12.         Map<String, String> emailsData = new LinkedHashMap<>();
  13.         String name = scanner.nextLine();
  14.  
  15.         while (!name.equals("stop")) {
  16.             String email = scanner.nextLine();
  17.             //съхраняваме данни само за хора, на които имейла не завършва на: uk, us, com
  18.             if (!email.endsWith("uk") && !email.endsWith("us") && !email.endsWith("com")) {
  19.                 emailsData.put(name, email);
  20.             }
  21.             name = scanner.nextLine();
  22.         }
  23.  
  24.         //име -> имейл
  25.         emailsData.entrySet().forEach(entry -> System.out.println(entry.getKey() + " -> " + entry.getValue()));
  26.     }
  27. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement