
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check If a String Is Palindrome Using Recursion
Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function.
Following is an example to find palindrome of a given number using recursive function.
Example
public class PalindromeRecursion { public static boolean isPalindrome(String str){ if(str.length() == 0 ||str.length()==1){ return true; } if(str.charAt(0) == str.charAt(str.length()-1)){ return isPalindrome(str.substring(1, str.length()-1)); } return false; } public static void main(String args[]){ String myString = "malayalam"; if (isPalindrome(myString)){ System.out.println("Given String is a palindrome"); }else{ System.out.println("Given String is not a palindrome"); } } }
Output
Given String is a palindrome
Advertisements