簡體   English   中英

為什么我在Java中遇到stackoverflow?

[英]Why am I encountering stackoverflow in Java?

我有一個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希望位於if塊之外

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM