My question is simply:
- Is it possible else statements are not guaranteed in some instances(excluding when, break, continue or return is called beforehand)?
For example: in this code an else statement follows at the end with a return call, but the error: [This method must return a result of type Boolean]. It is as if there is a possibility the else will not be called if the "if" statement is false.
public static boolean palindrome(String s){
if (s.length() == 1 ){
return false;
}
else if (s.length() == 2 ){
if(s.toLowerCase().trim().charAt(0) >= 'a' && s.toLowerCase().trim().charAt(0) <= 'z' && s.toLowerCase().trim().charAt(0) == s.toLowerCase().trim().charAt(s.length())){
return true;
}
else return false;
}
else if(s.toLowerCase().trim().charAt(0) >= 'a' && s.toLowerCase().trim().charAt(0) <= 'z'){
if(s.toLowerCase().trim().charAt(s.length()-1) >= 'a' && s.toLowerCase().trim().charAt(s.length()-1) <= 'z'){
if(s.toLowerCase().trim().charAt(0) == s.toLowerCase().trim().charAt(s.length()-1))
return true && palindrome(s.substring(1,s.length()-1));
}
else return palindrome(s.substring(0, s.length()-1));
}
}