-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaMap.java
More file actions
60 lines (34 loc) · 1.45 KB
/
JavaMap.java
File metadata and controls
60 lines (34 loc) · 1.45 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//Complete this code or write your own from scratch
import java.util.*;
import java.io.*;
class JavaMap{
public static void main(String []argh)
{
Scanner sc = new Scanner(System.in);
HashMap<String,Integer> hts = new HashMap<String,Integer>();
int n = sc.nextInt();
int number; String name;
for(int i = 0 ; i < n ; i++){
name = "";
sc.nextLine();
name = sc.nextLine();
number = sc.nextInt();
hts.put(name , number);
}
while(n > 0){
sc.nextLine();
String query = sc.nextLine();
if(hts.containsKey(query)){
for(Map.Entry mts : hts.entrySet()){
System.out.println(mts.getKey() +"="+mts.getValue());
break;
}
}
else{
System.out.println("Not found");
}
n = n - 1;
}
//int query = sc.nextInt();
}
}