.) The following stack stores a stack of integers. Draw the stacks and determine what is the output of the following program? import java.util.*; public class TestStack1 { public static void main(String ... args) { Stack s = new Stack< >( ); s.push(-54); s.push(27); s.push(31); System.out.println(s.pop( )); Integer v = s.pop( )+ s.pop( ) % 3; s.push(v); s.push(21); int w = s.pop( ); int x = s.pop( ); s.push(x % w - v); System.out.println(s.pop( )); Integer a=-2, b=5, c=22, d=4; s.push(a); s.push(b); s.push(c); s.push(d); s.push(s.pop( ) + s.pop( )); s.push(s.pop( ) * s.pop( )); while(!s.empty()) {System.out.println(s.pop( ));} } }
- .) The following stack stores a stack of integers.
Draw the stacks and determine what is the output of the following program?
import java.util.*;
public class TestStack1
{
public static void main(String ... args)
{
Stack<Integer> s = new Stack< >( );
s.push(-54);
s.push(27);
s.push(31);
System.out.println(s.pop( ));
Integer v = s.pop( )+ s.pop( ) % 3;
s.push(v);
s.push(21);
int w = s.pop( );
int x = s.pop( );
s.push(x % w - v);
System.out.println(s.pop( ));
Integer a=-2, b=5, c=22, d=4;
s.push(a);
s.push(b);
s.push(c);
s.push(d);
s.push(s.pop( ) + s.pop( ));
s.push(s.pop( ) * s.pop( ));
while(!s.empty())
{System.out.println(s.pop( ));}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images