为什么我在Java中遇到stackoverflow?
我有一个int,“count”,它在每次递归之后加一个,但我也有一个if语句,它在int等于或大于另一个整数时停止递归。不知何故,if语句被忽略了为什么我在Java中遇到stackoverflow?,java,recursion,stack-overflow,Java,Recursion,Stack Overflow,我有一个int,“count”,它在每次递归之后加一个,但我也有一个if语句,它在int等于或大于另一个整数时停止递归。不知何故,if语句被忽略了 public static boolean wildcard(String x, String y, int substring, int count) { if (count >= y.length()){ System.out.println("asdf"); return true; }
public static boolean wildcard(String x, String y, int substring, int count) {
if (count >= y.length()){
System.out.println("asdf");
return true;
}
if (x.charAt(count) == y.charAt(count)){
System.out.println("ALSKDFJKL");
return wildcard(x, y, substring, count++);
}
if (y.charAt(count) == '*'){
return wildcard(x.substring(substring), y, substring++, count);
System.out.println("wildcard end");
return false;
}
而不是
返回通配符(x,y,子字符串,count++)
try返回通配符(x,y,子字符串,++count)代码>
count++
是一个后期增量(意味着它将在方法返回后递增)
您可能还需要更新返回通配符(x.substring(substring),y,substring++,count)代码>出于同样的原因
另外,您的最后一个if
语句被破坏了……我认为系统.out
和返回false
想要在if
块之外,而不是返回通配符(x,y,子字符串,count++)
try返回通配符(x,y,子字符串,++count)代码>
count++
是一个后期增量(意味着它将在方法返回后递增)
您可能还需要更新返回通配符(x.substring(substring),y,substring++,count)代码>出于同样的原因
还有,你最后的if
语句被破坏了……我认为系统.out
和return false
想要在if
块之外你怎么知道if
语句被忽略了?因为如果它没有被忽略,递归就会结束。有人能解释我为什么会遇到堆栈溢出吗因为您有一个需要帮助回答的编程问题。如果忽略了语句,您如何知道呢?因为如果不忽略它,递归将结束。有人能解释我遇到stackoverflow的原因吗因为你有一个编程问题需要帮助回答。