Skip to content

Instantly share code, notes, and snippets.

@els-pnw
Created August 28, 2012 21:23
Show Gist options
  • Save els-pnw/3504479 to your computer and use it in GitHub Desktop.
Save els-pnw/3504479 to your computer and use it in GitHub Desktop.
static String reverse(String s) {
/*
* @param s
*/
while(s.length() != 0) {
/*
* Some learning code, to visualize what's going on
*/
System.out.println("The string " + s);
System.out.println("The substring 1 + length " + s.substring(1, s.length()));
System.out.println("The substring 0,1 " + s.substring(0,1));
/*
* The actual recursion code, keep this.
*/
return reverse(s.substring(1, s.length())) +
s.substring(0,1);
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment