1) I'm getting the error message incompatible types: boolean cannot be converted to java.lang.String. I've researched a bit, but I'm not entirely sure why I'm apparently trying to convert a boolean to a String.
2) Also I interpreted they were asking me to code for the following checks:
- the string not to be empty
- the n to be within a certain range
but their solution has no conditions.
The problem reads:
"Given a non-empty string and an int n, return a new string where the char at index n has been removed. The value of n will be a valid index of a char in the original string (i.e. n will be in the range 0..str.length()-1 inclusive).
your method definition says that a String will be returned (line 1). However, in line 9 you return a boolean. That is not a String, so the compiler gives you that error
But you do not need that checking at all. If you look at the constraints of the exercise, they guarantee that the input will be valid. So, in particular, the String cannot be empty, since then no index would be valid, and the index is always minimal 0 and maximal s.length() - 1.
There are three kinds of actuaries: those who can count, and those who can't.
posted 1 week ago
Hi Piet, thanks
Of course! The method type needs to match the return type.. *facepalm. I was thinking that the error was in my boolean logic... but its the return type. Got it.