我不断收到错误
Palindrome.java:36:错误:缺少返回语句 } ^ 1 错误
当我尝试编译时,对于实验室我必须有一个递归方法,如果输入字符串是忽略非字母字符的回文,则返回 true。那么问题是什么,我该如何解决它。
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;
}