Sample input: Java is robustPROGRAM:
REVERSING A STRING USING RECURSION
output: tsubor si avaJ
SYNTAX
import java.io.*;
public class rev_str_rec
{
static String s,n="";
public static void main(String args[])throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("ENTER A STRING TO REVERSE");
s=br.readLine();
int l=s.length();
reverse(l-1);
}
public static void reverse(int l)
{if(l>-1)
{
n+=s.charAt(l);
l--;
reverse(l);
}
else
System.out.println("REVERSED STRING: "+n);
}
}
Comments
Post a Comment