Web Development

বাদ দেন ফাকিবাজি পোস্ট ০১: String in reverse order using recursive method

/*-----------------------------------------------------------------------------!
! Output string in reverse order using recursive method                        !
!------------------------------------------------------------------------------!
! Notes:                                                                       !
! Original author: Md. Shaiful Islam (palash)                                  !
! Date: 01-July-2011                                                           !
===============================================================================*/

package programmingpractise;

public class ReverseString {

    private static String inputString = "Who are you?";
    private static int length=0;

    public static void main(String args[]){
        length = inputString.length();
        reversStringOutput(0);
    }


    private static void reversStringOutput(int index){
        if(index == length)
            return;
        char currentChar = inputString.charAt(index);
        reversStringOutput(index+1);
        System.out.print(currentChar);
    }

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s