I want to reverse the order of my output using stack and queues in Java.
Here is my code:
import java.util.*;
public class Books {
public static void main(String[] args) {
Queue<String> book = new LinkedList<String>();
Stack<String> Title = new Stack<>();
Scanner user = new Scanner(System.in);
System.out.println("Enter four book titles.");
int b = 4;
for (int i = 1; i <= b; i++) {
System.out.print("Book " + i + ": ");
String Enter = user.nextLine();
book.offer(Enter);
}
System.out.println("New order of books:");
System.out.println(book);
}
}
Here is the output of this code.
Enter four book titles.
Book 1: wew1
Book 2: wew2
Book 3: wew3
Book 4: wew4
New order of books:
[wew1, wew2, wew3, wew4]
What I was trying to is to make it in reverse order. But I don't know what to do.