|Jun29-04, 11:16 PM||#1|
Would you tell me how to write a test_function to check a given string whether it is a palindrome or not in Java recursively ?
|Jun29-04, 11:25 PM||#2|
The initial condition of the recursion is that the function is checking the first and last characters to see if they're the same. In other words, the recursive function is called with two arguments: (0, string.length() - 1). I will call those arguments a and b.
The function checks the two characters at the positions (a and b) given by the arguments. If they are not the same, the function return false.
If they are the same, the function first checks to see if it has met the condition to complete the check. If a and b are the same number, the recursion has reached the center of an odd-length palindrome. If b is one greater than a, then the recursion has reached the center of an even-length palindrome. If either of these conditions is true, the function returns true. If these conditions are not true, the check is not complete yet, and the function calls itself with arguments (a+1, b-1), and returns whatever result that call returns.
|Jun30-04, 05:41 AM||#3|
Many Thanks to Warren, I understand and made my program work fine as what you told me, Thanks a lot,
|Similar Threads for: Palindrome check|
|determines whether or not it is a palindrome||Engineering, Comp Sci, & Technology Homework||12|
|Check Please||Introductory Physics Homework||1|
|please check over||Introductory Physics Homework||3|
|Check This Please.||Introductory Physics Homework||10|