-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixEmails.java
More file actions
46 lines (38 loc) · 1.17 KB
/
FixEmails.java
File metadata and controls
46 lines (38 loc) · 1.17 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
package FixEmails;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class FixEmails {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Map<String,String> map = new HashMap<>();
int rowCounter = 1;
String person = null;
while(true){
String input = scanner.nextLine();
if("stop".equals(input))
break;
if(rowCounter %2 == 1){
map.put(input,null);
}
else{
if(input.endsWith(".us") ||
input.endsWith(".uk") ||
input.endsWith(".com")){
boolean isAvailable = map.containsKey(person);
if(isAvailable){
map.remove(person);
}
}
else{
map.put(person,input);
}
}
rowCounter++;
person = input;
}
for (Map.Entry<String, String> s : map.entrySet()) {
System.out.printf("%s -> %s%n",s.getKey(),s.getValue());
}
}
}