You are viewing a single comment's thread. Return to all comments →
Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); HashMap<String,Integer> phonebook = new HashMap<String,Integer>(); for(int i=0;i<n;i++){ String name = sc.nextLine(); int phonenumber = sc.nextInt(); phonebook.put(name,phonenumber); sc.nextLine(); } while(sc.hasNext()){ String search = sc.nextLine(); if(phonebook.containsKey(search)){ System.out.println(search+"="+phonebook.get(search)); }else{ System.out.println("Not found"); } } sc.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 →
Java Map Solution