Answers for "palindrome logic in java"

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
0

Palindrome string program in java using scanner

class Main
{
public static void main(String args[])
{
String a, b = "";
Scanner in = new Scanner(System.in);
System.out.println("Enter the string");
a = in.nextLine();
int length = a.length();
for (int i = length - 1; i >= 0; i--)
b = b + a.charAt(i);
if(a.equals(b))
System.out.println("The string is a palindrome.");
else
System.out.println("The string is not a palindrome.");
}
}
Posted by: Guest on June-12-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language