Display an Array Stack Bottom to Top
easyQuestion 414The stack works, but printing one shows nothing useful. Build the text yourself so System.out.println(stack) is readable.
Requirements:
1. Complete toString() so it starts with the label Stack: and then lists the values from the bottom of the stack up to the top.
2. Separate the values with single spaces, written after each value.
3. An empty stack shows the label on its own, with no values.
Do NOT write a main method.
Expected output
Stack: Stack: 10 20 30 Stack: 10 20
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Data Structures & AlgorithmsStacks
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.