Errors with missing return statement. Anyone have any idea what’s wrong with the code?
import java.text.*;
public class Sentence {
private String text;
public Sentence(String str) {
str = text;
}
public boolean isPalindrome() {
int length = text.length();
for(int n = 0;n <= length/2;n++) {
char letterFromFront = text.charAt(n);
char letterFromBack = text.charAt(length);
if(letterFromFront == letterFromBack) {
return true;
}else {
return false;
}
}
}
}
Its complaining because there won’t be any return if it doesn’t enter in the
forloop.Please add a
returnstatement afterforloop.Also please note:
n++in yourforloop is a dead code as your returning in the first iteration itself.