Opening Hours :7AM to 9PM
import java.util.Arrays; class ArrayRotate { public void leftRotate(int[] arr, int n, int k) { int i, j, temp; for (i = 0; i < gcd(n, k); i++) { temp = arr[i]; j = i; while (true) { int d = j + k; if (d >= n) { d = d - n; } if (d == i) { break; } arr[j] = arr[d]; j = d; } arr[j] = temp; } } public int gcd(int n, int k) { if (k == 0) { return n; } else { return gcd(k, n % k); } } } public class Main { public static void main(String[] args) { ArrayRotate ar=new ArrayRotate(); int[] arr = {1, 2, 3, 4, 5}; int n = arr.length; int k = 4; ar.leftRotate(arr, n, k); System.out.println(Arrays.toString(arr)); } }This program uses the concept of "juggling" to rotate the elements of the array. It first uses the gcd (greatest common divisor) of the array length and the number of rotations to determine the number of sets. Then, it repeatedly swaps the elements in each set until all elements have been moved to their final positions.