I need help rotating an array by a distance according to keyIndex.
Here is my code:
char[] arr = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int keyIndex = 2;
char[] newArr = new char[26];
int last = arr[arr.length -1];
for (int i = 0; i < arr.length; i++) {
arr[i] = arr[i + keyIndex];
}
but I get an error and the last two characters are not being saved in elements 0, 1.
My teacher said this can be solved somehow by using modulus division in one line.
lastused for? (it's nothing at the moment, so you should delete it from your code)newArrused for?