Answers for "how to check if string is palindrome in java using recursion"

6

Java program to check whether string is palindrome using library methods

public class StringPalindromeJava
{
   public static void isPalindrome(String str)
   {
      String strReverse = new StringBuffer(str).reverse().toString();
       // checking for palindrome
      if(str.equals(strReverse))
      {
         System.out.println(str + " is palindrome string.");
      }
      else
      {
         System.out.println(str + " is not palindrome string.");
      }
   }
   public static void main(String[] args)
   {
      // palindrome java
      isPalindrome("eye");
      isPalindrome("rotator");
   }
}
Posted by: Guest on November-02-2020
1

Java program to check palindrome number using recursion

// Java program to check palindrome number using recursion
public class PalindromeNumberRecursion
{
   static int palindromeRecursion(int number, int temp)
   {
      if(number == 0)
         return temp;
      // storing reverse of a number
      temp = (temp * 10) + (number % 10);
      return palindromeRecursion(number / 10, temp);
   }
   public static void main(String[] args)
   {
      int number = 141;
      int temp = palindromeRecursion(number, 0);
      if(temp == number)
      {
         System.out.println("number is palindrome.");
      }
      else
      {
         System.out.println("number is not palindrome.");
      }
   }
}
Posted by: Guest on February-19-2021

Code answers related to "how to check if string is palindrome in java using recursion"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language