Question

Print Reverse of given word using recursion

				
					ENTER THE WORD
rain
REVERSE OF WORD rain IS niar
				
			

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;
public class ReverseOfWord
{

    public static String FindReverse(String wd,int i)
    {

        if(i>=0)
        {
            return wd.charAt(i)+ FindReverse(wd,i-1);

        }
        else
        {
            return "";  
        }
    }

    public static void main()
    {
        String word="";
        Scanner sc=new Scanner(System.in);
        System.out.println("ENTER THE WORD");
        word=sc.next();

        System.out.print("REVERSE OF WORD "+word+" IS "+FindReverse(word,word.length()-1));

    }

}

    

				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *