Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

Java Source Code


Welcome to Dream.In.Code
Become a Java Expert!

Join 306,725 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,591 people online right now. Registration is fast and FREE... Join Now!





Reverse a String Using Recursion

This snippet returns the reverse of the given input from the beginning to the character at index.

Submitted By: macosxnerd101
Actions:
Rating:
Views: 185

Language: Java

Last Modified: November 2, 2009
Instructions: Make sure index is < input.length()-1

Snippet


  1. public String reverse(String input, int index){
  2.      //if the index is at the beginning, return the first character
  3.      if(index == 0) return input.charAt(0) + "";
  4.  
  5.      //otherwise, return the character at index plus the character
  6.      //immediately to the left   
  7.      return input.charAt(index) + reverse(input, index-1);
  8. }

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month