I've coded to check whether the number is palindrome or not. In my code, both the str
and string
variable returns same string. But the function returns false.
Where am I missing?
public class PalindromeDemo {
public static void main(String[] args) {
if(isPalindrome("aba")) {
System.out.println("The given no is palindrome");
}
}
static boolean isPalindrome(String str) {
StringBuilder string = new StringBuilder();
for(int i=1; i <= str.length(); i++) {
string.append(str.charAt(str.length()-i));
}
if(string.equals(str))
return true;
return false;
}
}