java - Can someone explain why I'm encountering stackoverflow? -


i have int, "count" adds 1 after each recursion, have if statement stops recursion once int equal to, or greater integer. somehow if statement ignored.

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

instead of return wildcard(x, y, substring, count++); try return wildcard(x, y, substring, ++count);

count++ post increment (meaning increment after method returns)

you want update return wildcard(x.substring(substring), y, substring++, count); same reason.

also, last if statement broken...i think system.out , return false want outside if block


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -