java - Morse code decoding - 1 word -
i working on encoding/decoding morse code program in java. i'm having trouble decoding. i'm working strictly uppercase alphabet , 1 word. no sentences. when debugged, program infinitely loops between lines 1 & 2. here have far:
m[0] = .-; m[25] = --..; string decode (string m) { m = m + " "; string temp = ""; string word = ""; { temp = m.substring(0,m.indexof(" ")); //line 1 (int = 0; < m.length(); i++) { if (temp.equals(m[i])){ // line 2 word += (char)i + 'a'; m = m.substring(m.indexof(" " + 1)); } } } while (m.contains(" ")); return word; }
try changing line inside loop this:
m = m.substring(m.indexof(" ")+1);
Comments
Post a Comment