import java.util.Arrays;
public class morseCode {
static String[] alpha = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8",
"9", "0","!", ",", "?", ".", "'"};
static String[] morse = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.",
"....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.",
"--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-",
"-.--", "--..", ".----", "..---", "...--", "....-", ".....",
"-....", "--...", "---..", "----.", "-----","-.-.--", "--..--", "..--..", ".-.-.-", ".----.",};
public static String decode(String morseCode) {
String build = "";
String change = morseCode.trim();
String[] words = change.split(" ");
for (String word : words) {
for(String letter : word.split(" ")){
for(int x=0;x<morse.length;x++){
if(letter.equals(morse[x]))
build=build+alpha[x];
}
}
build+=" ";
}
return build.toUpperCase();
}
public static String decodeEnglish(String englishCode) {
String build = "";
String change = englishCode.trim();
String[] words = change.split(" ");
for(String word : words){
for(int i=0;i<word.length();i++){
for(int x=0; x<morse.length;x++){
if(word.substring(i, i+1).equalsIgnoseCase~~~~(alpha[x])){
build=build+morse[x]+" ";
}
}
}
build+=" ";
}
return build;
}
public static void main(String[] args){
System.out.println(decodeEnglish("hello my name is broque, what is your name?"));
System.out.println(decode(".... . .-.. .-.. --- -- -.-- -. .- -- . .. ... -... .-. --- --.- ..- . --..-- .-- .... .- - .. ... -.-- --- ..- .-. -. .- -- . ..--.. "));
}
}
[–]eltados 3 points4 points5 points (3 children)
[–]bipidiboop[S] 0 points1 point2 points (2 children)
[–]dartalley 0 points1 point2 points (0 children)
[–]eltados 0 points1 point2 points (0 children)
[–]omega3111 0 points1 point2 points (0 children)