import java.util.*;
import java.lang.*;
import java.io.*;
//Write a program that reads an integer array A from input and modifies the array by shifting each element to the right by one position and by shifting the last element to the first position. Return the modified array.
// The main method must be in a class named "Main".
/*Suppose we have an array named array of size size, and the initial elements are
[3, 6, 9, 12, 15].
int lastElement = array[size - 1]; - This line stores the value of the last element in the array, 
which is 15, in the variable lastElement.
for (int i = size - 1; i > 0; i--) { - This for loop starts from the second-last element of the array 
(i.e., index size - 1) and iterates backwards until index 1.
array[i] = array[i - 1]; - Inside the loop, each element is shifted one position to the right. For instance:
array[4] = array[3], which makes the array [3, 6, 9, 12, 12]
array[3] = array[2], which makes the array [3, 6, 9, 9, 12]
array[2] = array[1], which makes the array [3, 6, 6, 9, 12]
array[1] = array[0], which makes the array [3, 3, 6, 9, 12]
After the loop finishes execution, the first element (array[0]) will still hold the value of lastElement 
that was stored initially.
    */

class Main {
    public static void main(String[] args) {
       // System.out.println("Hello world!");
       Scanner scn = new Scanner(System.in);
        int Size = scn.nextInt();
        int[] arr = new int[Size];
        
        for (int i= 0 ; i<Size ; i++)
            {
             arr[i] = scn.nextInt() ;
                
            }

        int lastelement = arr[Size-1];
for (int i= Size-1; i >0  ;i-- )
    {
        arr[i] = arr[i-1]    ;
    }
        arr[0] = lastelement;

for (int i= 0; i <Size ;i++ )
    {
   System.out.print(arr[i] +" ");

    }
        
        

            
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: