Question: A stack can be used to convert decimal numbers to binary numbers. You are to write the method displayBinary that will convert a decimal number
public static void displayBinary (int decimalNum){
Stack stck=new Stack();
while decimalNum not equal to 0{
find remainder when decimalNum is divided by 2
push remainder on the stack
divide the decimalNum by 2
}
while stack isn't empty
pop num off the stack and display
}
Use the following header in writing your method displayBinary.
/**
Display the binary representation of decimalNum.
Precondition: decimalNum>0
*/
public static void displayBinary (int decimalNum)
Step by Step Solution
There are 3 Steps involved in it
import javautil DecimalToBinaryUsingStacks public class DecimalToBinar... View full answer
Get step-by-step solutions from verified subject matter experts
