-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetPhoneNoFromPhoneBook.java
44 lines (33 loc) · 1.01 KB
/
GetPhoneNoFromPhoneBook.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class GetPhoneNoFromPhoneBook {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
String name = in.nextLine();
int phone = in.nextInt();
HashMap<String,Integer> map = new HashMap<String,Integer>();
map.put("Sneha", 12345678);
map.put("Krishna", 98765432);
map.put("abcd", 47489404);
map.put("lkm", 96648492);
map.put("dfg", 54321897);
Integer ph = map.get(name);
System.out.println(name +" = "+ ph);
/*Set<Map.Entry<String,Integer>> set = map.entrySet();
Iterator<Map.Entry<String,Integer>> itr = set.iterator();
while(itr.hasNext()){
Map.Entry<String,Integer> o = (Map.Entry<String,Integer>)itr.next();
String s = o.getKey();
if(s.equals(name)){
System.out.println(s+" = "+ o.getValue());
}else{
continue;
//System.out.println("Not Found");
}
}*/
}
}