Translate

Wednesday 4 July 2012

Write java code to check whether the given string is palindrome or not

import java.io.*;
class Palindrome
{
public static void main(String args[]) throws IOException
{
String str;
System.out.println("Enter a string");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
str=br.readLine();
StringBuffer sb=new StringBuffer(str);
String revstr=new String(sb.reverse());
if(revstr.equalsIgnoreCase(str))
System.out.println("Palindrome String!");
else
System.out.println("Not a Palindrome String!");
}
}

No comments:

Post a Comment