In this HackerRank Java Map problem, you are given a phone book that consists of people's names and phone numbers. After that, you will be given some person's name as a query. For each query, print the phone number of that person.

HackerRank Java Map problem solution

HackerRank Java Map problem solution

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



class Solution{
    public static void main(String []argh)
    {



        HashMap<String, Integer> hash = new HashMap<>();
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        in.nextLine();
        for(int i=0;i<n;i++)
        {
            String name=in.nextLine();
            int phone=in.nextInt();
            in.nextLine();
            hash.put(name,phone);
        }
        while(in.hasNext())
        {
            String s=in.nextLine();
            try
            {
                int out=hash.get(s);
                System.out.println(s+"="+out);
            }
            catch(Exception e)
            {
                System.out.println("Not found");
            }
        }


    }
}