CJCoding With Joseph
15free / daySign inCreate account

Display an Array Stack Bottom to Top

The 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 — print one after the last line.

Hints4 available
Topics:
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.