Skip to content

Commit 3fac215

Browse files
committed
Fix
1 parent 9d13f58 commit 3fac215

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/main/java/com/thealgorithms/conversions/MorseCodeConverter.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,18 @@ private MorseCodeConverter() {
6262
* @return The Morse code representation of the text.
6363
*/
6464
public static String textToMorse(String text) {
65-
StringBuilder morse = new StringBuilder();
66-
String[] words = text.toUpperCase().split(" ");
67-
for (int i = 0; i < words.length; i++) {
68-
for (char c : words[i].toCharArray()) {
69-
morse.append(MORSE_MAP.getOrDefault(c, "")).append(" ");
70-
}
71-
if (i < words.length - 1) {
72-
morse.append("| ");
65+
StringBuilder morse = new StringBuilder();
66+
String[] words = text.toUpperCase().split(" ");
67+
for (int i = 0; i < words.length; i++) {
68+
for (char c : words[i].toCharArray()) {
69+
morse.append(MORSE_MAP.getOrDefault(c, "")).append(" ");
70+
}
71+
if (i < words.length - 1) {
72+
morse.append("| ");
73+
}
7374
}
75+
return morse.toString().trim();
7476
}
75-
return morse.toString().trim();
76-
}
7777

7878
/**
7979
* Converts Morse code to text.
@@ -83,16 +83,16 @@ public static String textToMorse(String text) {
8383
* @return The text representation of the Morse code.
8484
*/
8585
public static String morseToText(String morse) {
86-
StringBuilder text = new StringBuilder();
87-
String[] words = morse.split(" \\| ");
88-
for (int i = 0; i < words.length; i++) {
89-
for (String code : words[i].split(" ")) {
90-
text.append(REVERSE_MAP.getOrDefault(code, '?'));
91-
}
92-
if (i < words.length - 1) {
93-
text.append(" ");
86+
StringBuilder text = new StringBuilder();
87+
String[] words = morse.split(" \\| ");
88+
for (int i = 0; i < words.length; i++) {
89+
for (String code : words[i].split(" ")) {
90+
text.append(REVERSE_MAP.getOrDefault(code, '?'));
91+
}
92+
if (i < words.length - 1) {
93+
text.append(" ");
94+
}
9495
}
96+
return text.toString();
9597
}
96-
return text.toString();
97-
}
9898
}

0 commit comments

Comments
 (0)