diff --git a/DecimalBinaryStack.java b/DecimalBinaryStack.java new file mode 100644 index 0000000..e9cc027 --- /dev/null +++ b/DecimalBinaryStack.java @@ -0,0 +1,29 @@ +import java.util.*; +class +{ + public static void main(String[] args) + { + Scanner in = new Scanner(System.in); + + // Create Stack object + Stack stack = new Stack(); + + // User input + System.out.println("Enter decimal number: "); + int num = in.nextInt(); + + while (num != 0) + { + int d = num % 2; + stack.push(d); + num /= 2; + } + + System.out.print("\nBinary representation is:"); + while (!(stack.isEmpty() )) + { + System.out.print(stack.pop()); + } + System.out.println(); + } +}