Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Write a program that receives an array and number of rotations you have to perform (first element goes at the end) Print the resulting array.
- */
- import java.util.Scanner;
- public class Exc04ArrayRotation {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] arr = scanner.nextLine().split(" ");
- int nRotations = scanner.nextInt();
- for (int i = 0; i < nRotations; i++) {
- String tempValue = arr[0];
- for (int j = 0; j < arr.length - 1; j++) {
- arr[j] = arr[j+1];
- }
- arr[arr.length -1] = tempValue;
- }
- System.out.println(String.join(" ",arr));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement