English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I want it to be recursive method. I think my base case is screwed up.

public static boolean palin(String str){
int begIndex = 0; //begining index
int endIndex = str.length() - 1; //ending index


if(str.length() <= 0)
return true;
else if(str.charAt(begIndex) == str.charAt(endIndex)){

str = str.substring(begIndex + 1, endIndex);

palin(str);
}

return false;


}

2007-12-03 14:02:02 · 2 answers · asked by Jake L 3 in Computers & Internet Programming & Design

2 answers

You may be incrementing the begIndex, but you're not decrementing the endIndex.

2007-12-03 14:13:09 · answer #1 · answered by Kasey C 7 · 1 0

When you use recursive functions, your return value goes to the line:

palin(str);

Unfortunately, you are not doing anything with that value. You should "return palin(str); " then it will make the true go all the way back.

Good luck mate.

2007-12-10 22:03:12 · answer #2 · answered by blake 2 · 0 0

fedest.com, questions and answers