Given a word the task is to check whether it is a Palindromic Word or not.
A Palindromic Word is a word which can be spelled same if it is reversed.
Example 1: Consider a word “LEVEL”. When reversed it is also “LEVEL”. Hence it is a Palindromic Word.
Example 2: Consider a word “TEST”. When reversed it is “TSET”. Here the reverse of the original word is not equal and cannot be spelled. Hence it is not Palindromic Word.
Java
import java.util.*;
public class PalindromeWord
{
public static void main(String args[])
{
int l=0;
char ch=' ';
String str="",rev="";
Scanner sc=new Scanner(System.in);
System.out.print("Enter the string: ");
str=sc.nextLine();
str=str.trim();
l=str.length();
for (int i=0;i<l;i++)
{
ch=str.charAt(i);
rev=ch+rev;
}
if(str.compareTo(rev)==0)
{
System.out.println("It is a Palindromic Word");
}
else
{
System.out.println("It is not a Palindromic Word");
}
}
}Java