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();if(n<0||n>100000){thrownewIllegalArgumentException("The number of people-phones cannot be lower than 0 or greater than 100,000");}Map<String,Integer>phoneBook=newHashMap<>();in.nextLine();for(inti=0;i<n;i++){Stringname=in.nextLine().toLowerCase();Integerphone=in.nextInt();in.nextLine();if(String.valueOf(phone).length()!=8){thrownewIllegalArgumentException(String.format("The phone number %s is not 8 digits long",phone));}phoneBook.put(name,phone);}while(in.hasNext()){Strings=in.nextLine().toLowerCase();Integerphone=phoneBook.get(s);if(phone==null){System.out.println("Not found");}else{System.out.println(String.format("%s=%d",s,phone));}}}}
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 →