Skip to main content

Posts

Showing posts with the label reverse string

REVERSING A STRING USING RECURSION

PROGRAM: REVERSING A STRING USING RECURSION Sample input: Java is robust 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); } }