JavaAlgorithms/reverse string.java

25 lines
529 B
Java
Raw Normal View History

2017-04-09 21:31:09 +08:00
import java.io.*;
class stringreverse
{
String reverseString(String str)
{
String reverse=" ";
if(str.length()==1)
{
return str;
}
else
{
reverse=reverse+str.charAt(str.length()-1)+reverseString(str.substring(0,str.length()-1));
return reverse;
}
}
public static void main(String args[])
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the string");
String srr=br.readLine();
System.out.println("Reverse="+reverseString(srr));
}
}