anyone helps me figure out what is wrong with my isPalindrome(int) function?
Basically this function checks if a number is a palindrome, and I wanted to accomplish this by recursion. Some problem occurs when isPalindrome(int) is called within the function. This brought my a lot of headache. Thanks!
public boolean isPalindrome(int num) {
String s = Integer.toString(num);
if( s.length() == 1 ) {
return true;
}
if( s.length() == 2 && s.charAt(0) == s.charAt(1) ) {
return true;
}
if( s.length() > 2 ) {
if(s.charAt(0) == s.charAt(s.length()-1))
s = s.substring(1, s.length()-1);
**isPalindrome(Integer.parseInt(s));**
}
return false;
}