I keep getting the error
Palindrome.java:36: error: missing return statement } ^ 1 error
when i try to compile, for the lab I have to have a recursive method which returns true if the input string is a palindrome ignoring non letter characters. So what is the problem and how do i go about fixing it.
package lab07;
import java.util.Scanner;
public class Palindrome{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
while ( input.hasNext()){
String line = normalise(input.next());
System.out.println(isPalindrome(line));
}
}
public static String normalise(String line){
String s = "";
char[] chars = line.toCharArray();
for (int i = 0; i < chars.length; i++){
if ( Character.isLetter(chars[i]))
s += Character.toLowerCase(chars[i]);
}
return s;
}
public static boolean isPalindrome(String line){
if ( line.length() > 1 ){
if (line.charAt(0) == line.charAt(line.length()-1)){
isPalindrome(line.substring(1, line.length()-1));
}
else
return false;
}
else
return true;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…