String Palindrome

Aim:
To write a java program that checks whether a given string is a palindrome or not.

Description: 
First, accept a string from the keyboard using BufferedReader class of the java.io package. Create a StringBuffer class object and pass the String as an argument to that object. Call reverse() method of StringBuffer object such that the string in that object will get reverse. After converting that StringBuffer object into String type store it in another String variable. Now by making use of the equals method of String class compare two strings if both are equal then the given string is palindrome otherwise it is not a palindrome.

Program:
import java.io.*;
class Palindrome
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
System.out.print("Enter the string : ");
String s1=br.readLine();
StringBuffer sb = new StringBuffer( s1 );
sb.reverse();
String s2 = sb.toString();
System.out.println(“The reversed String is : “ + s2);
if( s1.equals(s2) )
System.out.println("Given String is palindrome");
else
System.out.println("Given String is not a palindrome");
}
}