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.
//Complete this code or write your own from scratchimportjava.util.*;importjava.io.*;classSolution{publicstaticvoidmain(String[]argh){Scannerin=newScanner(System.in);intn=in.nextInt();in.nextLine();HashMap<String,Integer>hm=newHashMap<String,Integer>();for(inti=0;i<n;i++){Stringname=in.nextLine();intphone=in.nextInt();hm.put(name,phone);in.nextLine();}while(in.hasNext()){Strings=in.nextLine();try{inttemp=hm.get(s);System.out.println(s+"="+temp);}catch(NullPointerExceptione){System.out.println("Not found");}}}}
Hope this helps.
Cookie support is required to access HackerRank
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 →
Here is my code
Hope this helps.