缺少Java中的return语句错误 [英] Missing return statement error in Java
本文介绍了缺少Java中的return语句错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在用Java编写一个回文测试员,用于我高中时的课程。我已经向老师求助了,他也很困惑。我希望stackoverflow上的社区可以帮助我。谢谢。
I am currently writing a palindrome tester in Java for a class I am taking in high school. I have asked my teacher for assistance and he is also confused as well. I was hoping the community on stackoverflow could help me out. Thank you.
public class Palindrome
{
private String sentence;
public Palindrome(String s)
{
sentence = s;
}
public boolean isPalindrome()
{
if(sentence.length() <= 1)
{
return true;
}
if(sentence.charAt(0) == sentence.charAt(sentence.length()-1))
{
sentence = sentence.substring(1, sentence.length()-1);
isPalindrome();
}
else
return false;
}
}
推荐答案
您需要 return isPalindrome();
。否则该方法在这种情况下不返回任何内容,并且声明它返回一个布尔值。
You need return isPalindrome();
. Otherwise the method isn't returning anything in that case, and it's declared to return a boolean.
这篇关于缺少Java中的return语句错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文