A String is said to be a Palindrome String if after reversing it, it results in the original string.

Example: MADAM, EYE, RADAR, CIVIC, etc.

The basic logic for checking Palindrome String is to calculate its length and then reverse it using a loop construct by running a loop and extracting characters from (N-1)th position to 0th position. Store the same in another variable and the compare result with original string.


/* Program to enter a String and check if it is Palindrome or not.*/
import java.util.*;
class PalindromeString
public static void main()
Scanner inp=new Scanner(System.in);

System.out.print("\n Enter String: ");
String s=inp.nextLine();
String z="";
char c;
int i,k=s.length();


if(z.equals(s)==true)   //Comparing Both Strings
  System.out.println(s+" is a Palindrome String");
  System.out.println(s+" is not a Palindrome String");


Enter String: REFER
REFER is a Palindrome String


CopyRight © 2019

CopyRight © 2019