-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoneBook.java
More file actions
25 lines (23 loc) · 867 Bytes
/
PhoneBook.java
File metadata and controls
25 lines (23 loc) · 867 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
package Ds.Achievers;
import java.util.HashMap;
import java.util.Scanner;
public class PhoneBook {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
HashMap<Integer, String> hashMap=new HashMap<Integer, String>();
System.out.println("how many entries to make?");
int size=sc.nextInt();
for (int i=0;i<size;i++){
String name=sc.next();
int number=sc.nextInt();
hashMap.put(number, name);
}
System.out.println("enter name to get the phone number(-1 to exit)");
String nameSearch=sc.next();
System.out.println(hashMap.containsValue(nameSearch));
for (int o : hashMap.keySet()) {
if (hashMap.get(o).equals(nameSearch))
System.out.println(nameSearch + "=" + o);
}
}
}