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