我的 ASCII 和莫爾斯數(shù)組代碼有問題。只要我知道轉(zhuǎn)換是正確的......代碼使用函數(shù)和轉(zhuǎn)換來拆分每個“000000”并將數(shù)字轉(zhuǎn)換為字母和單詞。我不完全確定它有什么問題,但 cmd 說:Morse.java:73: error: incompatible types: String cannot be converted to int return result; ^Morse.java:80: error: incompatible types: String cannot be converted to int return result; ^2個錯誤有什么幫助嗎?public class Morse{ public static String decode(String txt) { String[] words = txt.split("0000000"); String result = ""; for(int w=0; w<words.length; w++) { result += processWord(words[w]); } return result; } public static String processWord(String word) { String[] letter = word.split("000"); String result = ""; for(int l=0;l<letter.length;l++) { result += processChar(letter[l]); } return result; } public static int processChar(String letters) { String[] morseLetters = new String[26]; morseLetters[0] = "10111"; //A morseLetters[1] = "111010101"; //B morseLetters[2] = "11101011101"; //C morseLetters[3] = "1110101"; //D morseLetters[4] = "1"; //E morseLetters[5] = "101011101"; //F morseLetters[6] = "111011101";//G morseLetters[7] = "1010101";//H morseLetters[8] = "101"; //I morseLetters[9] = "1011101110111";//J morseLetters[10] = "111010111";// K morseLetters[11] = "1011101010";// L morseLetters[12] = "1110111"; //M morseLetters[13] = "1110001";//N morseLetters[14] = "11101110111"; //O morseLetters[15] = "10111011101"; //P morseLetters[16] = "1110111010111"; // Q morseLetters[17] = "1011101"; // R morseLetters[18] = "10101";//S morseLetters[19] = "111"; //T
1 回答

慕后森
TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個贊
你的方法processChar
被聲明為返回int
public static int processChar(String letters) {...}
在第 73 行和第 80 行中,您試圖返回一個字符串。您應(yīng)該更改方法的特征以返回String
對象,例如:
public static String processChar(String letters) {...}
添加回答
舉報(bào)
0/150
提交
取消