We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String []argh){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
Map phonebook=new HashMap<>();
for(int i = 0; i < n; i++){
String name = in.next();
int phone = in.nextInt();
phonebook.put(name,phone);
// Write code here
}
while(in.hasNext()){
String s = in.next();
//write your code here
if(phonebook.containsKey(s)) System.out.println(s+"="+phonebook.get(s));
else System.out.println("Not found");
}
in.close();
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 8: Dictionaries and Maps
You are viewing a single comment's thread. Return to all comments →
public static void main(String []argh){ Scanner in = new Scanner(System.in); int n = in.nextInt(); Map phonebook=new HashMap<>(); for(int i = 0; i < n; i++){ String name = in.next(); int phone = in.nextInt(); phonebook.put(name,phone); // Write code here } while(in.hasNext()){ String s = in.next(); //write your code here if(phonebook.containsKey(s)) System.out.println(s+"="+phonebook.get(s)); else System.out.println("Not found"); } in.close(); }