Untitled
unknown
plain_text
a year ago
861 B
2
Indexable
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class PhoneBook { public static void main(String[] args) { Map<String, Integer> phonebookMap = new HashMap<>(); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); for (int i = 0;i < n; i++){ String name = sc.nextLine(); int number = sc.nextInt(); sc.nextLine(); phonebookMap.put(name, number); } while (sc.hasNext()){ String person = sc.nextLine(); if (phonebookMap.containsKey(person)){ System.out.println(person + "=" + phonebookMap.get(person)); }else { System.out.println("Not found"); } } sc.close(); } }
Editor is loading...
Leave a Comment