Tuesday, December 13, 2011

java program to find out reverse of a string

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);

}
}

Output:
enter a string
sample
elpmas