Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedHashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class U5PhoneBook {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- Map<String, String> maps = new LinkedHashMap<>();
- while (!input.equals("search")) {
- String[] tokens = input.split("-");
- String name = tokens[0];
- String number = tokens[1];
- maps.put(name,number);
- input = scanner.nextLine();
- while (!input.equals("stop")) {
- String names = scanner.nextLine();
- if (!maps.containsKey(name)) {
- maps.put(name, number);
- System.out.printf("%s -> %s%n", name, number);
- } else {
- System.out.printf("Contact %s does not exist.%n", names);
- }
- }
- input = scanner.nextLine();
- }
- // for (Map.Entry<String, String> entry : maps.entrySet()) {
- // System.out.printf("%s -> %s%n", entry.getKey(), entry.getValue());
- // }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement