| Thread Closed |
Palindrome check |
Share Thread | Thread Tools |
| Jun29-04, 11:16 PM | #1 |
|
|
Palindrome check
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 ?
Thank you, -Pattielli |
| 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. - Warren |
| 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,
- Pattielli |
| Thread Closed |
| Thread Tools | |
Similar Threads for: Palindrome check
|
||||
| Thread | Forum | Replies | ||
| 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 | ||
| Palindrome | General Discussion | 25 | ||
| Check This Please. | Introductory Physics Homework | 10 | ||