# Palindrome check

1. Jun 29, 2004

### Pattielli

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

2. Jun 29, 2004

### chroot

Staff Emeritus
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

3. Jun 30, 2004

### Pattielli

Many Thanks to Warren, I understand and made my program work fine as what you told me, Thanks a lot,

- Pattielli