SHARE
TWEET

Untitled

a guest Jan 25th, 2020 62 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 U5PhoneBook {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String input = scanner.nextLine();
  10.         Map<String, String> maps = new LinkedHashMap<>();
  11.  
  12.  
  13.         while (!input.equals("search")) {
  14.             String[] tokens = input.split("-");
  15.             String name = tokens[0];
  16.             String number = tokens[1];
  17.  
  18.             maps.put(name,number);
  19.  
  20.             input = scanner.nextLine();
  21.             while (!input.equals("stop")) {
  22.                 String names = scanner.nextLine();
  23.  
  24.                 if (!maps.containsKey(name)) {
  25.  
  26.                     maps.put(name, number);
  27.                     System.out.printf("%s -> %s%n", name, number);
  28.  
  29.                 } else {
  30.                     System.out.printf("Contact %s does not exist.%n", names);
  31.  
  32.                 }
  33.  
  34.  
  35.             }
  36.             input = scanner.nextLine();
  37.         }
  38. //        for (Map.Entry<String, String> entry : maps.entrySet()) {
  39. //            System.out.printf("%s -> %s%n", entry.getKey(), entry.getValue());
  40. //        }
  41.  
  42.  
  43.     }
  44. }
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