public static boolean isPalindrome(String str){
StringBuilder sb=new StringBuilder(str);
sb.reverse();
String rev=sb.toString();
if(str.equals(rev)){
return true;
}else{
return false;
}
}
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
static boolean isPalindrome(String s)
{
/* Two pointers initialised to 0 and 's.length()-1'.*/
int i = 0, j = s.length() - 1;
/* Looping through the string */
while (i < j) {
/* Even if one character is not equal, we will return false. */
if (s.charAt(i) != s.charAt(j))
return false;
/* Value of pointers is changed */
i++;
j--;
}
/* This means all characters are same and thus string is a palindrome*/
return true;
}
public static void main(String[] args)
{
String s = "abba";
/* First, We'll convert it to lower case. */
s = s.toLowerCase();
if (isPalindrome(s))
System.out.print("Yes");
else
System.out.print("No");
}
}
//This function generates a palindrom by recursively reversing a String,
//recursively add it and checks if it's a palindrom
public static String generatePalindrom(String s) {
return s.equals(reverseString(s)) ? s
: generatePalindrom(String.valueOf(Integer.parseInt(s) + Integer.parseInt(reverseString(s))));
}
public static String reverseString(String s) {
return s.length() == 1 ? s : s.charAt(s.length() - 1) + reverseString(s.substring(0, s.length() - 1));
}