0

Phone book in Java

How to do this 🙄

9th Oct 2019, 3:46 AM
Rahul Sandeepa
Rahul Sandeepa - avatar
1 Réponse
0
This might help 😄 import java.util.*; import java.io.*; class Solution{ public static void main(String []argh){ Map<String,Integer> phoneBook = new HashMap<String,Integer>(); 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 = Integer.parseInt(in.nextLine()); phoneBook.put(name, phone); } while(in.hasNext()){ String s = in.nextLine(); Integer phoneNumber = phoneBook.get(s); System.out.println( (phoneNumber != null) ? s + "=" + phoneNumber : "Not found" ); } in.close(); } }
9th Oct 2019, 6:14 AM
rishabh
rishabh  - avatar