import java.util.*;
import java.lang.*;
import java.io.*;

// The main method must be in a class named "Main".
class Main {
    
    
    static int[] reverseArray(int arr[]){
        int l = 0; 
        int r = arr.length - 1; 
        
        while( l <= r){
            int temp = arr[l];
            arr[l] = arr[r];
            arr[r] = temp;
            l++;
            r--;
        }
        
        return arr;
    }
    
    
    // 1 2 3 4 5 6, index 1 to index 4 
    // 1 5 4 3 2 6 ( reversed the array partly)
    static int[] reverseArrayPartly(int arr[], int left, int right){
        int l = left; 
        int r = right; 
        
        while( l <= r){
            int temp = arr[l];
            arr[l] = arr[r];
            arr[r] = temp;
            l++;
            r--;
        }
        
        return arr;
    }
    
    
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        
        int arr[] = new int[n];
        for(int i = 0 ; i <n; i++){
            arr[i] = scn.nextInt();
        }
        
        
        int reversed[] = reverseArrayPartly(arr, 1, 4);
        
        for(int i = 0 ; i <n; i++){
            System.out.print(reversed[i] + " ");
        }
        
        
    }
}

Embed on website

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