0
0
Javaprogramming~15 mins

Stack memory in Java - Interactive Code Practice

Choose your learning style8 modes available
ads_clickPractice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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
AArrayList
BStack
CLinkedList
DHashSet
Attempts:
3 left
2fill in blank
medium

Complete 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
Apush
Badd
Cinsert
Doffer
Attempts:
3 left
3fill in blank
hard

Fix 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
Apoll
Bremove
Cpop
Ddelete
Attempts:
3 left
4fill in blank
hard

Fill 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
AisEmpty
Bempty
Cfull
Dclear
Attempts:
3 left
5fill in blank
hard

Fill 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
AStack
Bpush
Cpop
Dadd
Attempts:
3 left