View Code of Problem 79


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int  n= sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int m = sc.nextInt();
        /*for (int i = a.length-m; i < a.length; i++) {
            System.out.print(a[i]+" ");
        }
        for (int i = 0; i < a.length-m; i++) {
            if(i!=a.length-m-1)
                System.out.print(a[i]+" ");
            else
                System.out.println(a[i]);
        }*/
        List<Integer> list = new ArrayList<>();
        for (int i = a.length-m; i < a.length; i++) {
            list.add(a[i]);
        }
        for (int i = 0; i < a.length-m; i++) {
            list.add(a[i]);
        }
        for (int i = 0; i < list.size(); i++) {
            if(i!=list.size())
                System.out.print(list.get(i)+" ");
            else
                System.out.println(list.get(i));
        }
    }
}

Double click to view unformatted code.


Back to problem 79