Advertisement
bat_gogo

Untitled

May 24th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Scanner;
  5.  
  6. public class Phonebook {
  7. public static void main(String[] args) {
  8. Scanner input = new Scanner(System.in);
  9. HashMap<String, String> phonebook = new HashMap<>();
  10. String line = input.nextLine();
  11. while (!line.equals("search")) {
  12. String[] temp = line.split("-");
  13. String name = temp[0];
  14. String number = temp[1];
  15. phonebook.put(name, number);
  16. line = input.nextLine();
  17. }
  18. if (line.equals("search")) {
  19. line = input.nextLine();
  20. while (!line.equals("stop")) {
  21. if (phonebook.containsKey(line)) {
  22. System.out.printf("%s -> %s\n", line, phonebook.get(line));
  23.  
  24. } else {
  25. System.out.printf("Contact %s does not exist.\n", line);
  26. }
  27. line = input.nextLine();
  28. }
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement