decimal to binary using stack
import java.util.*;
public class ConvertDecimalToBinaryUsingStack {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number: ");
int num = input.nextInt();
Stack stack = new Stack();
if (num == 0) {
System.out.println("BINARY is 0000");
} else if (num == 1) {
System.out.println("Binary is: 0001");
} else {
while (num != 0) {
int a = num / 2;
int b = num % 2;
stack.push(b);
num = a;
}
}
while (!stack.empty()) {
System.out.print(stack.pop());
}
System.out.println(" ");
}
}