Skip to content

Instantly share code, notes, and snippets.

@Todd-Davies
Last active August 29, 2015 14:12
Show Gist options
  • Save Todd-Davies/af119fe01a81f30a4bbf to your computer and use it in GitHub Desktop.
Save Todd-Davies/af119fe01a81f30a4bbf to your computer and use it in GitHub Desktop.
import java.util.Arrays;
public class part1c {
public static char[] shift(char[] input, int shiftNum) {
char[] firstHalf = Arrays.copyOfRange(input, 0, shiftNum);
char[] secondHalf = Arrays.copyOfRange(input, shiftNum, input.length);
for(int i = 0; i < (input.length - shiftNum); i++) {
input[i] = secondHalf[i];
}
for(int i = (input.length - shiftNum); i < input.length; i++) {
input[i] = firstHalf[i - (input.length - shiftNum)];
}
return input;
}
public static void main(String[] args) {
char[] arr = {'a','b','c','d','e','f','g'};
System.out.println(shift(arr, 3));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment