hacker rank java 32th problem solution(java map)

32. JAVA MAP


import java.util.*;
import java.io.*;

class Solution{
   public static void main(String []argh)
   {
      Scanner in = new Scanner(System.in);
      int n=in.nextInt();
      in.nextLine();
      HashMap<String, Integer> hm = new HashMap<String, Integer>();
     
      for(int i=0;i<n;i++)
      {
         String name=in.nextLine();
         int phone=in.nextInt();
         hm.put(name, phone);       
         in.nextLine();
      }
      while(in.hasNext())
      {
         String s=in.nextLine();
         try{
            int temp = hm.get(s);
            System.out.println(s+"="+temp);
         }catch(NullPointerException e){
            System.out.println("Not found");
         }   
      }
   }
}



Compiler Message
Success
Input (stdin)Download
3
uncle sam
99912222
tom
11122222
harry
12299933
uncle sam
uncle tom
harry
{-truncated-}
Download to view the full testcase
Expected OutputDownload
uncle sam=99912222
Not found
harry=12299933
{-truncated-}
Download to view the full testcase

Comments

Popular posts from this blog

Amazon Web Services

Google Code-In mentorship experience :)

Hacker Rank all java and python problem solutions