Advertisement
Krassi_Daskalova

ArrayRotation

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