Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DPM;
- import java.util.Scanner;
- import java.util.TreeMap;
- public class Main {
- public static void main(String[] args){
- Scanner scan = new Scanner(System.in);
- String line ;
- TreeMap<String, String> phoneBook = new TreeMap<>();
- while (!"search".equals(line = scan.nextLine())) {
- String[] name = line.split("-");
- phoneBook.put(name[0], name[1]);
- }
- line = scan.nextLine();
- while (!line.equals("stop")) {
- if (!phoneBook.containsKey(line)){
- System.out.println("Contact " + line + " does not exist.");
- }else if (phoneBook.containsKey(line)){
- System.out.println(line + " -> " + phoneBook.get(line));
- }
- line = scan.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement