You are viewing a single comment's thread. Return to all comments →
import java.util.HashMap; import java.util.Scanner;
public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); scanner.nextLine();
HashMap<String, String> phoneBook = new HashMap<>(); // Read n phone book entries for (int i = 0; i < n; i++) { String name = scanner.nextLine(); String phoneNumber = scanner.nextLine(); phoneBook.put(name, phoneNumber); } // Look up phone numbers for m queries while (scanner.hasNext()) { String name = scanner.nextLine(); String phoneNumber = phoneBook.get(name); if (phoneNumber != null) { System.out.println(name + "=" + phoneNumber); } else { System.out.println("Not found"); } } scanner.close(); }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Java Map
You are viewing a single comment's thread. Return to all comments →
import java.util.HashMap; import java.util.Scanner;
public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); scanner.nextLine();
}