// to print a string in reverse order using recursion
import java.io.*;
class reverseString
{
public static void main(String args[])throws IOException
{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a String: ");
String s=br.readLine();
reverse(s, s.length());
}
public static void reverse(String S, int a)throws IOException
{
System.out.print(S.charAt(--a));
if(a>0)
reverse(S,a);
}
}
No comments:
Post a Comment