Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Arrays;
- public class SoftUni {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter your array here: ");
- String[] stringArr = sc.nextLine().split(" ");
- int[] intArr = Arrays.stream(stringArr).mapToInt(e -> Integer.parseInt(e)).toArray();
- System.out.print("Enter the number of rotations you want(1st element becomes last with a rotation performed): ");
- int rotations = Integer.parseInt(sc.nextLine());
- for(int i = 0;i<rotations;i++){
- int temp = intArr[0];
- for(int m = 0;m<intArr.length-1;m++){
- intArr[m] = intArr[m+1];
- }
- intArr[intArr.length-1] = temp;
- }
- for(int i: intArr){
- System.out.print(i + " ");
- }
- }
- }
Add Comment
Please, Sign In to add comment