gpt4 book ai didi

java - 为什么我在 Java 中遇到 stackoverflow?

转载 作者:行者123 更新时间:2023-11-29 07:58:47 25 4
gpt4 key购买 nike

我有一个 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;
}

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;
}

最佳答案

代替 return wildcard(x, y, substring, count++); 试试 return wildcard(x, y, substring,++count);

count++ 是一个后递增(意味着它会在方法返回后递增)

出于同样的原因,您可能还想更新 return wildcard(x.substring(substring), y, substring++, count);

此外,您的最后一个 if 语句被破坏了...我认为 System.outreturn false 想要在 如果 block

关于java - 为什么我在 Java 中遇到 stackoverflow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15825572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com