1public static boolean isPalindrome(String str){
2 StringBuilder sb=new StringBuilder(str);
3 sb.reverse();
4 String rev=sb.toString();
5 if(str.equals(rev)){
6 return true;
7 }else{
8 return false;
9 }
10}
1//This function generates a palindrom by recursively reversing a String,
2//recursively add it and checks if it's a palindrom
3
4public static String generatePalindrom(String s) {
5 return s.equals(reverseString(s)) ? s
6 : generatePalindrom(String.valueOf(Integer.parseInt(s) + Integer.parseInt(reverseString(s))));
7}
8
9public static String reverseString(String s) {
10 return s.length() == 1 ? s : s.charAt(s.length() - 1) + reverseString(s.substring(0, s.length() - 1));
11}