import java.util.*;
import java.io.*;
class reverse
{
public static void main(String args[])throws Exception
{
int i;
String s1="";
System.out.println("enter a string");
BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
String s= k.readLine();
int n=s.length();
for(i=n-1;i>=0;i--)
s1=s1+s.charAt(i);
System.out.println(s1);
if(s1.equals(s))
System.out.println("Palindrome");
else
System.out.println("Not a Palindrome");
}
}
Output:
enter a string
madam
madam
Palindrome
import java.io.*;
class reverse
{
public static void main(String args[])throws Exception
{
int i;
String s1="";
System.out.println("enter a string");
BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
String s= k.readLine();
int n=s.length();
for(i=n-1;i>=0;i--)
s1=s1+s.charAt(i);
System.out.println(s1);
if(s1.equals(s))
System.out.println("Palindrome");
else
System.out.println("Not a Palindrome");
}
}
Output:
enter a string
madam
madam
Palindrome