-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek8.java
More file actions
51 lines (50 loc) · 1.25 KB
/
week8.java
File metadata and controls
51 lines (50 loc) · 1.25 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
import java.util.*;
public class week8 {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
int n=sc.nextInt();
Employee[] e=new Employee[n];
for(int i=0;i<n;i++){
e[i]=new Employee();
e[i].setId(sc.nextInt());
e[i].setName(sc.next());
e[i].setAge(sc.nextInt());
}
HashMap<Integer,Employee> h =new HashMap<>();
for(int i=0;i<n;i++){
h.put(e[i].getId(),e[i]);
}
int j=sc.nextInt();
for(int i:h.keySet()){
Employee p = h.get(i);
if(i==j){
System.out.println(p.getName()+p.getAge());
System.exit(0);
}
}
System.out.println("Not found");
}
static class Employee{
private String name;
private int id;
private int age;
void setId(int id){
this.id=id;
}
void setAge(int age){
this.age=age;
}
void setName(String name){
this.name=name;
}
int getId(){
return id;
}
int getAge(){
return age;
}
String getName(){
return name;
}
}
}