Question
check whether a word is palindrome or not
A palindrome word is a word that reads the same backward as forward, such as madam or racecar.
Enter a word:mom
mom is a Palindrome word
Enter a word:weather
weather is not a Palindrome word
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Share code with your friends
Code
Java
Python
Java
import java.util.Scanner;
public class checkPalindromeWord
{
public static void main(String[] args)
{
String wd="",wd1="";
char ch=' ';
int i=0,len=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a word");
wd = sc.next();
System.out.println("given word:"+wd);
len=wd.length();
for(i=0;i< len;i++)
{
ch=wd.charAt(i);
wd1=ch+wd1;
}
if(wd1.equals(wd)==true)
{
System.out.println(wd+" is a palindrome word");
}
else
{
System.out.println(wd+" is not a palindrome word");
}
}
}
Python
word=input("Enter a word:")
lengthOfWord=len(word)
ch=' '
reverseOfWord=""
for i in range(0,lengthOfWord):
ch=word[i]
reverseOfWord=ch+reverseOfWord
# You can also replace from line 3 to 7 with
# reverseOfWord=word[::-1]
# it will do the same thing
if(word==reverseOfWord):
print(word,"is a Palindrome word")
else:
print(word, "is not a Palindrome word")