Question: What does the following code fragment print when N = 43? Stack stack = new Stack(); while (N > 0) { stack.push(N % 2); N

What does the following code fragment print when N = 43?

Stack stack = new Stack();

while (N > 0) {

stack.push(N % 2);

N = N/2; }

for (int d : stack) StdOut.print(d);

StdOut.println();

1. 101010

2. 001011

3. 101000

4. 101111

5. 101011

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!