我的 ASCII 和莫尔斯数组代码有问题。只要我知道转换是正确的......代码使用函数和转换来拆分每个“000000”并将数字转换为字母和单词。我不完全确定它有什么问题,但 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贡献1802条经验 获得超5个赞
你的方法processChar
被声明为返回int
public static int processChar(String letters) {...}
在第 73 行和第 80 行中,您试图返回一个字符串。您应该更改方法的特征以返回String
对象,例如:
public static String processChar(String letters) {...}
添加回答
举报
0/150
提交
取消