Skip to content

Commit f15cd43

Browse files
author
codehouseindia
authored
Merge pull request codehouseindia#104 from amit14mitra/patch-2
Added Java Map Program
2 parents 91e3b79 + c2104ad commit f15cd43

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

MapDemo.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* Here is given a phone book that consists of people's names and their phone number.
2+
After that I will take some person's name as query.
3+
For each query I print the phone number of that person. */
4+
5+
import java.util.*;
6+
import java.io.*;
7+
8+
class Solution{
9+
public static void main(String []argh)
10+
{
11+
Scanner in = new Scanner(System.in);
12+
int n=in.nextInt();
13+
in.nextLine();
14+
Map<String,Integer> m=new HashMap<String,Integer>();
15+
for(int i=0;i<n;i++)
16+
{
17+
String name=in.nextLine();
18+
int phone=in.nextInt();
19+
m.put(name,phone);
20+
in.nextLine();
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+
else
28+
System.out.println("Not found");
29+
}
30+
}
31+
}
32+
33+
34+

0 commit comments

Comments
 (0)