You can do this with a pair of loops, but it's not that simple. In this case, using recursion is easier.
public static void main(String... args) { for (int i = 0; i < 12; i++) { int[] ints = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; rotateLeft(ints, i); System.out.println(Arrays.toString(ints)); } } public static void rotateLeft(int[] array, int num) { rotateLeft(array, num, 0); } private static void rotateLeft(int[] array, int num, int index) { if (index >= array.length) return; int tmp = array[(index + num) % array.length]; rotateLeft(array, num, index + 1); array[index] = tmp; }
prints
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1] [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2] [4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3] [5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4] [6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5] [7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6] [8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7] [9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8] [10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9] [11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]