Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.*;
  5.  
  6. public class Main {
  7. public static void main(String[] args) throws IOException {
  8. Scanner scanner = new Scanner(System.in);
  9. Map<String, String> map = new LinkedHashMap<>();
  10.  
  11. String input = scanner.nextLine();
  12.  
  13. while (!input.equals("search")) {
  14. String[] tokens = input.split("-");
  15. String name = tokens[0];
  16. String number = tokens[1];
  17. map.put(name, number);
  18.  
  19. input = scanner.nextLine();
  20.  
  21.  
  22. }
  23. input = scanner.nextLine();
  24. while (!input.equals("stop")) {
  25.  
  26.  
  27. if (map.containsKey(input)) {
  28.  
  29. {
  30. for (String string : map.keySet()) {
  31. if (string.equals(input)) {
  32. System.out.printf("%s -> %s%n", string, map.get(input));
  33. }
  34.  
  35. }
  36.  
  37.  
  38. }
  39. } else
  40. System.out.printf("Contact %s does not exist.%n", input);
  41. input = scanner.nextLine();
  42.  
  43.  
  44. }
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement