i'm practicing recursion problems,
That's the question :
Given a string, compute recursively (no loops) the number of lowercase 'x' chars in the string.
countX("xxhixx") → 4
countX("xhixhix") → 3
countX("hi") → 0
that's my code :
the 4th line has unreachable statement errorpublic int countX(String str) { if (str.length() == 0); return 0; if (str.charAt(0) == 'x') // <---- unreachable statement here return 1 + countX(str.substring(1)); return countX(str.substring(1)); }
i can't find a reason why is it unreachable because the first statement is wrapped in an if statement :/
i'll appreciate any help
thanks !