-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhonebook.java
31 lines (28 loc) · 1.08 KB
/
Phonebook.java
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
package Exercises;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
public class Phonebook {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Map<String,String> listOfPhoneNumbers = new LinkedHashMap<>();
String input = scan.nextLine();
while(!input.equals("search")){
String information[] = input.split("-");
String name = information[0];
String number = information[1];
listOfPhoneNumbers.put(name,number);
input = scan.nextLine();
}
String nameToBeFound = scan.nextLine();
while(!nameToBeFound.equals("stop")){
if(listOfPhoneNumbers.containsKey(nameToBeFound)){
String number = listOfPhoneNumbers.get(nameToBeFound);
System.out.println(nameToBeFound + " -> " + number );
}else{
System.out.printf("Contact %s does not exist.%n",nameToBeFound);
}
nameToBeFound= scan.nextLine();
}
}
}