Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions DecimalBinaryStack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.util.*;
class
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);

// Create Stack object
Stack<Integer> stack = new Stack<Integer>();

// 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();
}
}