import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
*
* @author pankaj
*/
public class stringpalindrome
{
public static void main(String[] args)
{
try {
System.out.print("enter a string : ");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String str=in.readLine();
String temp=str;
String f="";
char c = 0;
for(int i=str.length()-1;i>=0;i--)
{ c=str.charAt(i);
String s=Character.toString(c);
f=f.concat(s);
}
if(temp.equals(f))
{
System.out.print("palindrome");
}
else
System.out.print("Not a palindrome");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
No comments:
Post a Comment