Menu
Question Index
...

Write a program to rotate elements of given array to right by K positions.

Input (int[], int) Output (int[])
{1, 2, 3, 4, 5, 6, 7, 8}, 2 {7, 8, 1, 2, 3, 4, 5, 6}
{1, 2, 3, 4, 5, 6, 7, 8}, 5 {4, 5, 6, 7, 8, 1, 2, 3}
{20, 6, 8, 11, 30}, 3 {8, 11, 30, 20, 6}
{12, 15, 19, 1, 33}, 1 {33, 12, 15, 19, 1}
{5, 6, 7, 8, 9, 10}, -2 {5, 6, 7, 8, 9, 10}
{4, 6, 5, 7, 1}, 11 {1, 4, 6, 5, 7}



class RotateArrayElementsRightByKPositions
{
    public static void main(String s[])
    {
        int inputArray[] = {3, 4, 5, 6, 7, 8};
        int K = 5;
        rotateRight(inputArray, K);
        System.out.println("After rotating array to right by " + K + " postions we get");
        for (int element : inputArray)
        System.out.print(element + " ");

    }


    public static void rotateRight(int inputArray[], int K) {
    }

}

Doubts

Problems

Topic: Learn Arrays And Loops

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App