Question: A String is said to be Palindrome if it is equal to itself in reverse order. Some of the possibilities are Remove the first character.

 A String is said to be Palindrome if it is equal

A String is said to be Palindrome if it is equal to itself in reverse order. Some of the possibilities are Remove the first character. Remove the last character. Remove both the first and last characters. Remove a character from the middle. Cut the string into two halves. Easiest way to find if a given String is Palindrome or not is by writing a recursive function to reverse the String first and then comparing given String with the reversed String, if both are equal then given String is palindrome. You can write a method called reverse(String str), which is responsible for reversing given String using recursion. This method take out the last character and passed the rest of the String to the reverse() method itself, when a method calls itself is called recursion. A recursive function needs a based case to terminate recursion and produce result. In this program, base case is empty String, if String is empty just return itself and don't call the method. You can use substring() method from java.lang.String class to reduce the String in every call so that the solution reaches to base case after every call. Write a recursive Java program to check if the a given user string is Palindrome or not. You can use any logic of yours or follow the logic mentioned above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!