Java problem to left rotate an array upto n times. It would be nice if anyone can review this code.
Task:
A left rotation operation on an array of size shifts each of the array's elements unit to the left. For example, if left rotations are performed on array , then the array would become .
Given an array of integers and a number, , perform left rotations on the array. Then print the updated array as a single line of space-separated integers.
solution
public class LeftRotateArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int Array_Size = in.nextInt();
int Rotation_Number = in.nextInt();
int arr[] = new int[Array_Size];
for (int i = 0; i < Array_Size; i++) {
arr[i] = in.nextInt();
}
for (int i = 0; i <= Array_Size - 1; i++) {
if (i < Array_Size - Rotation_Number)
System.out.print(arr[i + Rotation_Number] + "\t");
else
System.out.print(arr[i - Array_Size + Rotation_Number] + "\t");
}
}
}