Code a testing application. Your app must satisfy the following requirements: Cr
ID: 3671833 • Letter: C
Question
Explanation / Answer
import java.util.Stack;
public class StackDemo
{
public static void main(String args[])
{
int a=5;
// Create a new, empty stack
Stack lifo = new Stack(5);
// Let's add some items to it
for (int i = 1; i <= 4; i++)
{
lifo.push ( new Integer(i) );
}
System.out.println(lifo);
// Last in first out means reverse order
while ( !lifo.empty() )
{
System.out.print ( lifo.pop() );
System.out.print ( ',' );
}
if(lifo.empty())
{
lifo.push ( new Integer(a) );
System.out.println(lifo);
}
if(lifo.empty())
{
}
else
lifo.push ( new Integer(a) );
}
for (int i = 1; i <= 5; i++)
{
lifo.push ( new Integer(i) );
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.