Java Left Rotate Array upto n times 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 &lt; Array_Size; i++) {
            arr[i] = in.nextInt();
        }
        for (int i = 0; i &lt;= Array_Size - 1; i++) {
            if (i &lt; Array_Size - Rotation_Number)
                System.out.print(arr[i + Rotation_Number] + "\t");

            else
                System.out.print(arr[i - Array_Size + Rotation_Number] + "\t");

        }
    }

}
As people have already pointed out you have to actually rotate the array.To do that  a really cool way would be using the mod(%) operator so even if the Rotation_Number variable that you are using is greater than the array length your code will run fine.

Declare a new array 

   int arrRotated[] = new int[Array_Size];


and to store and print the array 

    for (int i = 0; i &lt;= Array_Size - 1; i++) {
        arrRotated[i] = arr[(i+Rotation_Number)%arr.length];
        System.out.print(arrRotated[i]);
    }