Arrange the following code fragments to form a complete Java program that reads a line of space-separated words into a LinkedList<String>, then uses a ListIterator to print them in reverse order.
Computer scienceProgramming languagesJavaWorking with dataCollectionsCollection implementationsThe Collection hierarchy implementations
LinkedList
Iterator Shuffle
Report a typo
Reorder lines using drag or arrows. Adjust indentation with left buttons
import java.util.ListIterator;
}
LinkedList<String> list = new LinkedList<>();
list.add(token);
}
import java.util.Scanner;
}
}
for (String token : input.split("\\s+")) {
public class Main {
public static void main(String[] args) {
System.out.print(it.previous() + " ");
while (it.hasPrevious()) {
Scanner sc = new Scanner(System.in);
import java.util.LinkedList;
String input = sc.nextLine();
ListIterator<String> it = list.listIterator(list.size());
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.