Skip to content

Commit e9917b9

Browse files
authored
Create Morse.java
1 parent a8f2293 commit e9917b9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Easy-Level/Morse.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import java.io.*;
2+
import java.util.HashMap;
3+
4+
public class Main {
5+
private static HashMap<String, String> alphaMorse = new HashMap<String, String>();
6+
static {
7+
alphaMorse.put(".-", "A"); alphaMorse.put("-...", "B");alphaMorse.put("-.-.", "C");
8+
alphaMorse.put("-..", "D"); alphaMorse.put(".", "E");alphaMorse.put("..-.", "F");
9+
alphaMorse.put("--.", "G");alphaMorse.put("....", "H");alphaMorse.put("..", "I");
10+
alphaMorse.put(".---", "J");alphaMorse.put("-.-", "K");alphaMorse.put(".-..", "L");
11+
alphaMorse.put("--", "M");alphaMorse.put("-.", "N");alphaMorse.put("---", "O");
12+
alphaMorse.put(".--.", "P");alphaMorse.put("--.-", "Q");alphaMorse.put(".-.", "R");
13+
alphaMorse.put("...", "S");alphaMorse.put("-", "T");alphaMorse.put("..-", "U");
14+
alphaMorse.put("...-", "V");alphaMorse.put(".--", "W");alphaMorse.put("-..-", "X");
15+
alphaMorse.put("-.--", "Y");alphaMorse.put("--..", "Z");alphaMorse.put(".----", "1");
16+
alphaMorse.put("..---", "2");alphaMorse.put("...--", "3");alphaMorse.put("....-", "4");
17+
alphaMorse.put(".....", "5");alphaMorse.put("-....", "6");alphaMorse.put("--...", "7");
18+
alphaMorse.put("---..", "8");alphaMorse.put("----.", "9");alphaMorse.put("-----", "0");
19+
}
20+
21+
public static void main (String[] args) throws IOException {
22+
File file = new File(args[0]);
23+
BufferedReader br = new BufferedReader(new FileReader(file));
24+
String line;
25+
while ((line = br.readLine()) != null) {
26+
String[] a = line.split(" ");
27+
for (int i = 0; i < a.length; i++) {
28+
String[] b = a[i].trim().split(" ");
29+
for (String morse : b) {
30+
System.out.print(alphaMorse.get(morse));
31+
}
32+
System.out.print(" ");
33+
}
34+
System.out.println();
35+
}
36+
br.close();
37+
}
38+
}

0 commit comments

Comments
 (0)