-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixEmails.java
More file actions
45 lines (37 loc) · 1.36 KB
/
Copy pathFixEmails.java
File metadata and controls
45 lines (37 loc) · 1.36 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
package Exercises;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
public class FixEmails {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String input = scan.nextLine();
String sameAsInput = input;
int count = 1;
String temporaryShelter = "";
Map<String,String> map = new LinkedHashMap<>();
while (!input.equals("stop")) {
if (count % 2 != 0) {
temporaryShelter = input;
} else {
String text = takeLastText(input);
if (!text.equals("us") && !text.equals("uk") && !text.equals("com")) {
map.put(temporaryShelter, input);
} else {
map.remove(temporaryShelter);
}
}
count++;
input = scan.nextLine();
}
for(Map.Entry<String, String> pair : map.entrySet()){
System.out.println(String.format("%s -> %s",pair.getKey(),pair.getValue()));
}
}
private static String takeLastText(String input) {
String[] text1 = input.split("@");
String text2 = text1[text1.length-1];
String[] text3 = text2.split("\\.");
return text3[text3.length-1].toLowerCase();
}
}