//Program to check whether the given string is palindrome or not
import java.util.*;
class Palindrome
{
public static void main(String args[])
{
String str;
int flag=0;
Scanner scr=new Scanner(System.in);
System.out.println(“nEnter any String:”);
str=scr.next();
int p=str.length();
char ch[]=str.toCharArray();
for(int i=p-1,j=0;i>=j;i–,j++)
{
if(ch[j]!=ch[i])
{
flag=1;
break;
}
}
if(flag==0)
System.out.println(“nGiven String is palindrome”);
else
System.out.println(“nGiven String is Not a palindrome”);
}
}
Output:
Enter any String:
madam
Given String is palindrome