Java Program to Convert a Decimal Number to Binary Number using Arrays as Stacks
Given an Integer number convert into Binary Number using arrays as a stack.
Input : 10 Output: 1010 Input : 16 Output: 10000
- Divide the number by 2 and store the remainder of the number in the array.
- Divide the number by 2.
- Repeat the process until the number becomes zero.
- Print the array in reverse order.
Binary equivalent: 101110
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.