Advertisement
deyanmalinov

05. Phonebook - Print

Jun 1st, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. package DPM;
  2. import java.util.Scanner;
  3. import java.util.TreeMap;
  4.  
  5. public class Main {
  6.     public static void main(String[] args){
  7.         Scanner scan = new Scanner(System.in);
  8.         String line ;
  9.         TreeMap<String, String> phoneBook = new TreeMap<>();
  10.  
  11.         while (!"search".equals(line = scan.nextLine())) {
  12.             String[] name = line.split("-");
  13.             phoneBook.put(name[0], name[1]);
  14.         }
  15.         line = scan.nextLine();
  16.         while (!line.equals("stop")) {
  17.  
  18.             if (!phoneBook.containsKey(line)){
  19.                 System.out.println("Contact " + line + " does not exist.");
  20.             }else if (phoneBook.containsKey(line)){
  21.                 System.out.println(line + " -> " + phoneBook.get(line));
  22.             }
  23.             line = scan.nextLine();
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement