1import java.util.Scanner;
2public class RecursivePalindromeJava
3{
4 // to check if string is palindrome using recursion
5 public static boolean checkPalindrome(String str)
6 {
7 if(str.length() == 0 || str.length() == 1)
8 return true;
9 if(str.charAt(0) == str.charAt(str.length() - 1))
10 return checkPalindrome(str.substring(1, str.length() - 1));
11 return false;
12 }
13 public static void main(String[]args)
14 {
15 Scanner sc = new Scanner(System.in);
16 System.out.println("Please enter a string : ");
17 String strInput = sc.nextLine();
18 if(checkPalindrome(strInput))
19 {
20 System.out.println(strInput + " is palindrome");
21 }
22 else
23 {
24 System.out.println(strInput + " not a palindrome");
25 }
26 sc.close();
27 }
28}
1// Java program to check palindrome number using recursion
2public class PalindromeNumberRecursion
3{
4 static int palindromeRecursion(int number, int temp)
5 {
6 if(number == 0)
7 return temp;
8 // storing reverse of a number
9 temp = (temp * 10) + (number % 10);
10 return palindromeRecursion(number / 10, temp);
11 }
12 public static void main(String[] args)
13 {
14 int number = 141;
15 int temp = palindromeRecursion(number, 0);
16 if(temp == number)
17 {
18 System.out.println("number is palindrome.");
19 }
20 else
21 {
22 System.out.println("number is not palindrome.");
23 }
24 }
25}