In idea code works.
I initialized LinkedList, but code checker sais that not.
package com.codegym.task.task07.task0711;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;
/*
Remove and insert
1. Create a list of strings.
2. Add 5 strings from the keyboard.
3. Do the following 13 times: remove the last string and insert it at the beginning.
4. Use a loop to display the resulting list, each value on a new line.
Requirements:
1. Declare a string list variable and immediately initialize it.
2. The program should read 5 strings from the keyboard.
3. Remove the last string and insert it at the beginning. Rinse and repeat 13 times.
4. The program should display the list, each value on a new line.
*/
public class Solution {
public static void main(String[] args) throws Exception {
LinkedList<String> sList = new LinkedList<>();
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 5; i++) {
sList.add(scanner.nextLine());
}
for (int i = 0; i < 13; i++) {
sList.addFirst(sList.getLast());
sList.removeLast();
}
sList.stream().forEach(System.out::println);
}
}