Write a Java Program to Check String is Palindrome or not using Recursion

By | March 12, 2017

Java Program to Check String is Palindrome or not using Recursion


Write a Java Program to Check String is Palindrome or not using Recursion. Here is our Java program, which checks if a given String is palindrome or not. Program is simple and here are steps to find palindrome String :

  • Reverse the given String
  • Check if reverse of String is equal to itself, if yes then given String is palindrome.

  • A String is nothing but a collection of characters e.g. “keyword” and String literals are encoded in double quotes in Java.
  • A String is said to be a palindrome if the reverse of String is equal to itself e.g. “mom” is a palindrome because the reverse of “mom” is also “mom”, but “java” is not a palindrome because the reverse of “java” is “avaj” which is not equal.
  • Recursion means solving a problem by writing a function which calls itself. In order to check if String is a palindrome in Java, we need a function which can reverse the String.
  • Once you have original and reversed String, all you need to do is check if they are equal to each other or not. If they are equal then String is palindrome or not. You can write this reverse() function by using either for loop or by using recursion.

The following code accepts a string, and checks whether the given string is Palindrome or not using Recursion. The Program below is successfully compiled and run on the Windows System to produce desired output.


 

SOURCE CODE : :


 


OUTPUT : :


 

Leave a Reply