And this is my code.

public class Solution {

public void rotate(int[] nums, int k) {

int n = nums.length;// length n of the array

```
if(k < 0 || k == n) {
return;
}
if(k > n) {
k = k % n;
}
int[] newNums1 = new int[n - k];// new a new array for the first part of the array
int[] newNums2 = new int[k];// new a new array for the second part of the array
int[] newNums = new int[n];// new a new array for the rotated array
for(int i = 0; i < n - k; i++) {
newNums1[i] = nums[i];
}
for(int i = 0; i < k; i++) {
newNums2[i] = nums[n - k + i];
}
for(int i = 0; i < k; i++) {
newNums[i] = newNums2[i];
}
for(int i = k;i < n ; i++) {
newNums[i] = newNums1[i - k];
}
}
```

}