高分悬赏:用Java语言编写一个莫斯电报的编码的程序,然后选择一段英文字符串,对其编码、输出

高分悬赏:用Java语言编写一个莫斯电报的编码的程序,然后选择一段英文字符串,对其编码、输出

class Test
{
    static char[] english = { 
        '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 = { 
        ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", 
        ".---", "-.-", ".-..", "--", "-.", "---", ".---.", "--.-", ".-.",
        "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", ".----",
        "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.",
        "-----", "--..--", ".-.-.-", "..--.." };
    private static String getMorse(char ch){
        for(int i=0;i<english.length;i++) {
            if(english[i] == ch){
                return morse[i];
            }
        }
        return "?";
    }
    public static String getMorse(String str){
        String result = "";
        for(int i=0;i<str.length();i++)
        {
           result += getMorse(str.charAt(i)); 
        }
        return result; 
    }
    public static void main(String[] args){
        System.out.println(getMorse("hello"));
    }
}