Question: Question: Write a program that converts decimal to binary using a stack. Ask the user to enter a decimal number, then print the equivalent binary

Question: Write a program that converts decimal to binary using a stack. Ask the user to enter a decimal number, then print the equivalent binary number.

1) Add a method to the Stack class print() to print the contents starting with the earliest to the latest. Eg: stk.push(3); stk.push(4); stk.push(5); stk.print(); //would print 3 4 5

2) Write a method public long removeSecond (): It removes and returns the element just below the top element if the stack has at least two elements, otherwise it simply returns null without modifying the stack Eg: stk.push(3); stk.push(4); stk.push(5); stk.push(6); stk.removeSecond(); stk.print(); //would print 3 4 6

StackTest.java

class StackTest { public static void main(String[] args) { StackX theStack = new StackX(10); // make new stack theStack.push(20); // push items onto stack theStack.push(40); theStack.push(60); theStack.push(80);

theStack.print(); theStack.removeSecond(); System.out.println("After removeSecond()"); theStack.print(); } // end main() }

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!