-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSem2_T3_20.java
More file actions
30 lines (27 loc) · 996 Bytes
/
Sem2_T3_20.java
File metadata and controls
30 lines (27 loc) · 996 Bytes
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
import java.io.*;
import java.util.*;
// There is one txt file in D Drive --> read data and entry in HashMap.
public class Sem2_T3_20 {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
BufferedReader br = new BufferedReader(new FileReader("D:\\data1.txt"));
String l = br.readLine();
HashMap<Integer, String> h = new HashMap<>();
while (l != null) {
String s[] = l.split(" ", 2);
int x = Integer.parseInt(s[0]);
String w = s[1];
h.put(x, w);
l = br.readLine();
}
System.out.println(h); // {1=rrr, 2=abc, 3=xyz}
System.out.print("Enter Roll No. to know Name : ");
int r = sc.nextInt();
if (h.containsKey(r)) {
System.out.println(h.get(r));
} else {
System.out.println("Data not Found!!!");
}
br.close(); sc.close();
}
}