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