I was working on the assignment of summer Java and there was a problem with the recursive implementation of the indexOf method in Java. Here is what I still have:
public int rIndexOf(char ch, int fromPos) { int charPos = fromPos; if (charPos >= myString.length() || myString.equals("")) return -1; else if (myString.charAt(charPos) == ch) return charPos; else return charPos + rIndexOf(ch, charPos + 1); }
I seem to be getting values ββthat are completely wrong, so I can only imagine the problem with incrementing or counting, but isn't my code increasing charPos by +1 every time? Or is it related to ASCII character values?
I was also wondering if the string "charPos = fromPos" is needed at all. Can I just use fromPos throughout my code, or would I break the "missing link is not value"?
source share