Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Arrays_Exercise {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter numbers: ");
- String []numbers = sc.nextLine().split("\\s+");
- System.out.print("Number of rotations: ");
- int rotations = Integer.parseInt(sc.nextLine());
- for (int i = 0; i < rotations % numbers.length; i++) {
- String firstNumber = numbers[0];
- for (int j = 0; j < numbers.length -1 ; j++) {
- numbers[j] = numbers[j + 1];
- }
- numbers[numbers.length -1] = firstNumber;
- }
- System.out.println(String.join(", ", numbers));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment