Advertisement
meteor4o

JF-ArrayRotation

Jun 4th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ArrayRotation {
  4. public static void main(String[] args) {
  5.  
  6. Scanner sc = new Scanner(System.in);
  7.  
  8. String[] input = sc.nextLine().split(" ");
  9.  
  10. int n = Integer.parseInt(sc.nextLine());
  11.  
  12. n = n % input.length;
  13.  
  14. for (int i = 0; i < n ; i++) {
  15.  
  16.  
  17. String firstElement = input[0];
  18.  
  19. for (int k = 0; k < input.length - 1; k++) {
  20. input[k] = input[k + 1];
  21.  
  22. }
  23. input[input.length - 1] = firstElement;
  24. }
  25.  
  26. for (int i = 0; i < input.length; i++) {
  27. System.out.print(input[i] + " ");
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement