Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a stack of integers using Java's Stack class.
Java
Stack<Integer> numbers = new [1]<>();🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
2fill in blank
mediumComplete the code to add an element to the top of the stack.
Java
numbers.[1](10);
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
3fill in blank
hardFix the error in the code to remove the top element from the stack.
Java
int top = numbers.[1]();🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
4fill in blank
hardFill both blanks to check if the stack is empty and print a message.
Java
if (numbers.[1]()) { System.out.println("Stack is [2]."); }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
5fill in blank
hardFill all three blanks to create a stack, push two elements, and pop one.
Java
Stack<String> stack = new [1]<>(); stack.[2]("apple"); stack.[3]();
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
