Give the actual output of the fololowing code ArrayStack stk

Give the actual output of the fololowing code:

ArrayStack<Integer> stk=new ArrayStack<Integer>();
int x = 3, y = 19;
stk.push(new Integer(6));
stk.push(new Integer(x));
stk.push(new Integer(y));
System.out.println(stk.top());// Output 1_________
stk.pop();
Integer z1=(Integer)stk.top();
int z2=z1.intValue();
z2 =z2 * 4;
stk.pop();
stk.push(new Integer(z2));
stk.push(new Integer(35));
while (!stk.isEmpty()){
System.out.println(stk.top() + \" \"); // Output 2______
stk.pop();}

Solution

Answer :

Give the actual output of the fololowing code:

ArrayStack<Integer> stk=new ArrayStack<Integer>();
int x = 3, y = 19;
stk.push(new Integer(6));
stk.push(new Integer(x));
stk.push(new Integer(y));
System.out.println(stk.top());// Output 1_________
stk.pop();
Integer z1=(Integer)stk.top();
int z2=z1.intValue();
z2 =z2 * 4;
stk.pop();
stk.push(new Integer(z2));
stk.push(new Integer(35));
while (!stk.isEmpty()){
System.out.println(stk.top() + \" \"); // Output 2______
stk.pop();}

Answer :

System.out.println(stk.top());// Output 1_________

19

Explanation :

int x = 3, y = 19;
stk.push(new Integer(6));
stk.push(new Integer(x));        //    x=3
stk.push(new Integer(y));       //     y=19
System.out.println(stk.top());   // In stack first in last out.

So, Answer for 1st output is 19.

2nd output Answer is 19

Explanation :

stk.pop();
Integer z1=(Integer)stk.top();
int z2=z1.intValue();
z2 =z2 * 4;
stk.pop();
stk.push(new Integer(z2));
stk.push(new Integer(35));
while (!stk.isEmpty()){
System.out.println(stk.top() + \" \");

output :19

Give the actual output of the fololowing code: ArrayStack<Integer> stk=new ArrayStack<Integer>(); int x = 3, y = 19; stk.push(new Integer(6)); stk.p
Give the actual output of the fololowing code: ArrayStack<Integer> stk=new ArrayStack<Integer>(); int x = 3, y = 19; stk.push(new Integer(6)); stk.p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site