Thursday, March 26, 2009

java code to reverse a String

import java.io.*;
public class reverse1
{
public static void main(String [] x)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a Number");
Integer i=new Integer(br.readLine());
String ip=i.toString();
StringBuffer sf=new StringBuffer(ip);
String z=sf.reverse().toString();
System.out.println(z);
if(ip.equals(z))
System.out.println(" The Number "+ip+" is a palindrome");
else
System.out.println(" The Number "+ip+" is not a palindrome");

}
}

0 comments: