我在StackOverflow上寻找可能回答我的问题的其他示例,但其他问题中的答案都没有集中在嵌套for循环上.我正在制作一个莫尔斯代码翻译器,如果我这样做,程序本身也能正常工作:
public static void StringtoMorse(String str){
char Alphabet [] = {'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', ' '};
String MorseCode [] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", "|"};
for (int i = 0; i < str.length(); i ++){
for …Run Code Online (Sandbox Code Playgroud)