-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPhoneBook.java
More file actions
43 lines (30 loc) · 873 Bytes
/
PhoneBook.java
File metadata and controls
43 lines (30 loc) · 873 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
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.*;
public class PhoneBook {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Map<String, String> book = new HashMap<String, String>();
for (;;) {
System.out.println(
"\nWelcome to PhoneBook\n Enter 1 to add contact\n Enter 2 to search contact\n Enter 3 to exit\n");
int n = sc.nextInt();
sc.nextLine();
if (n == 1) {
System.out.println("Enter name: ");
String name = sc.nextLine();
System.out.println("Enter Number: ");
String number = sc.nextLine();
book.put(name, number);
System.out.println("Number " + number + " is saved by name " + name + "\n");
}
if (n == 2) {
System.out.println("Enter name: ");
String key = sc.nextLine();
System.out.println("Number: " + book.get(key) + "\n");
}
if (n == 3) {
break;
}
}
sc.close();
}
}