Advertisement
vov44k

Сдвиг 2-й способ

Feb 27th, 2022
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner in = new Scanner(System.in);
  7.  
  8.         int n;
  9.         n = in.nextInt();
  10.         int[] a = new int[n];
  11.         for (int i = 0; i < n; i++) {
  12.             a[i] = in.nextInt();
  13.         }
  14.  
  15.         int r;
  16.         r = in.nextInt();
  17.  
  18.         int[] tempArray = new int[r];
  19.         System.arraycopy(a, 0, tempArray, 0, r);
  20.  
  21.  
  22.         for (int i = 0; i < n-r; i++){
  23.             a[i] = a[i+r];
  24.         }
  25.  
  26.         System.arraycopy(tempArray, 0, a, n-r, r);
  27.         for (int i = 0; i < n; i++) {
  28.             System.out.print(a[i] + " ");
  29.         }
  30.  
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement