我有一个 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.out
和 return false
想要在 如果
block
关于java - 为什么我在 Java 中遇到 stackoverflow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15825572/