Skip to content

Commit 47beecc

Browse files
committed
Print Phone numbers
1 parent 4bdfa12 commit 47beecc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Java/Data-Structure/Map.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
You are given a phone book that consists of people's names and their phone number. After that you will be given some person's name as query. For each query, print the phone number of that person.
3+
*/
4+
5+
import java.util.*;
6+
import java.io.*;
7+
8+
class Map {
9+
public static void main(String []argh)
10+
{
11+
Scanner in = new Scanner(System.in);
12+
Map m = new HashMap();
13+
int n=in.nextInt();
14+
in.nextLine();
15+
for(int i=0;i<n;i++)
16+
{
17+
String name=in.nextLine();
18+
int phone=in.nextInt();
19+
in.nextLine();
20+
m.put(name,phone);
21+
}
22+
while(in.hasNext())
23+
{
24+
String s=in.nextLine();
25+
if (m.containsKey(s)) {
26+
System.out.println(s + "=" + m.get(s));
27+
}
28+
else {
29+
System.out.println("Not found");
30+
}
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)