How to check Palindrome Word in java ?

Code

import java.util.*;
class Palindrome
{
public static void SOP(String msg)
{
System.out.println(msg);
}
public static String strrev(String str)
{
return new StringBuilder(str).reverse().toString();
}
public static void main(String[] args)
{
SOP(“Enter any string->>”);
String str=new Scanner(System.in).next();
if(str.equals(strrev(str)))
SOP(“Palindrom Word”);
else SOP(“Not Palindrom Word”);
}
}

Output

Leave a Reply