Solved

Select an Appropriate Expression to Complete the Method Below, Which

Question 22

Multiple Choice

Select an appropriate expression to complete the method below, which is designed to print the element at the bottom of a Stack collection. The contents of the original stack are restored before the method terminates. It is safe to assume that the original stack contains at least one element. public static void printBottom(Stack<String> theStack)
{
Stack<String> anotherStack = new Stack<String>() ;
While (theStack.size() > 0)
{
AnotherStack.push(theStack.pop() ) ;
}
____________________________
While (anotherStack.size() > 0)
{
TheStack.push(anotherStack.pop() ) ;
}
}


A) System.out.println(theStack.pop() ) ;
B) System.out.println(theStack.peek() ) ;
C) System.out.println(anotherStack.peek() ) ;
D) System.out.println(anotherStack.pop() ) ;

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions