• + 0 comments

    Java Map Solution

    Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            sc.nextLine();
            
            HashMap<String,Integer> phonebook = new HashMap<String,Integer>();
            for(int i=0;i<n;i++){
                String name = sc.nextLine();
                int phonenumber = sc.nextInt();
                phonebook.put(name,phonenumber);
                sc.nextLine();
            }
            while(sc.hasNext()){
                String search = sc.nextLine();
                if(phonebook.containsKey(search)){
                    System.out.println(search+"="+phonebook.get(search));
                }else{
                    System.out.println("Not found");
                }
            }
            sc.close();