Opening Hours :7AM to 9PM
class ArrayRightRotate { public void rightRotate(int[] arr, int k, int n) { for (int i = 0; i < k; i++) { int temp = arr[n - 1]; for (int j = n - 2; j >= 0; j--) { arr[j + 1] = arr[j]; } arr[0] = temp; } } } public class Main { public static void main(String[] args) { ArrayRightRotate ar=new ArrayRightRotate(); int[] arr = {1, 2, 3, 4, 5}; int n = arr.length; int k = 2; // rotate by 2 elements ar.rightRotate(arr, k, n); for (int i = 0; i < n; i++) { System.out.print(arr[i] + " "); } } }The above program creates an array arr of integers and assigns it the values {1, 2, 3, 4, 5}. It then defines a variable k that represents the number of elements by which the array should be rotated to the right. In this case, k is set to 2, so the array will be rotated by 2 elements to the right.