-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavaMap.java
More file actions
38 lines (28 loc) · 1.09 KB
/
Copy pathjavaMap.java
File metadata and controls
38 lines (28 loc) · 1.09 KB
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
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine(); // clearing the buffer so that we can get our string
HashMap<String ,Integer> map = new HashMap<>();
for(int i=0;i<n;i++) {
String name = sc.nextLine();
int Contacts = sc.nextInt();
sc.nextLine(); // clearing the buffer so that we can get our string
//adding name & contact to map
map.put(name, Contacts);
}
while(sc.hasNext()) {
String existing = sc.nextLine();
try{
int contact = map.get(existing);
System.out.println(existing+"="+contact);
}
catch(Exception e){
System.out.println("Not found");
}
}
}
}