desislava_topuzakova

07. Fix Emails

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