Created
September 28, 2014 15:45
-
-
Save RyanNutt/cef101ed3f82db40613e to your computer and use it in GitHub Desktop.
I needed an easy way to rotate a string a set number of places for a lab I was setting up. This returns s rotated by distance spots and loops back around.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String rotateString(String s, int distance) { | |
String out = ""; | |
for (int i=0; i<s.length(); i++) { | |
out += s.charAt((i + distance) % s.length()); | |
} | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment