【发布时间】:2019-04-10 00:01:04
【问题描述】:
当我使用测试用例 find("mississippi", "sip") 运行我的代码时,它会在下面打印出“sippi”然后是“false”。我对此感到困惑,因为我假设“真实”会被打印出来。
我尝试删除 if 正文中的 return 语句,但出现错误
public static boolean find (String text, String str) //method to find "str" within "text"
{
if (text.substring(0, str.length()).equals(str))
{
System.out.println(text);
return true;
}
else
{
text = text.substring(1);
find(text, str);
System.out.println(text);
return false;
}
}
我希望输出是 sippi true,但实际输出是 sippi false
【问题讨论】: