Java Program for Decimal to Binary Conversion
Given a decimal number as input, we need to write a program to convert the given decimal number into equivalent binary number.
Examples:
Input : 7 Output : 111 Input : 10 Output : 1010 Input: 33 Output: 100001

Java
// Java program to convert a decimal // number to binary number import java.io.*; class GFG { // function to convert decimal to binary static void decToBinary(int n) { // array to store binary number int[] binaryNum = new int[1000]; // counter for binary array int i = 0; while (n > 0) { // storing remainder in binary array binaryNum[i] = n % 2; n = n / 2; i++; } // printing binary array in reverse order for (int j = i - 1; j >= 0; j--) System.out.print(binaryNum[j]); } // driver program public static void main (String[] args) { int n = 17; decToBinary(n); } } // Contributed by Pramod Kumar |
chevron_right
filter_none
Please refer complete article on Program for Decimal to Binary Conversion for more details!
Recommended Posts:
- Binary string with given frequencies of sums of consecutive pairs of characters
- LongStream.Builder build() in Java
- DoubleStream.Builder build() in Java
- Java 8 | Consumer Interface in Java with Examples
- MouseListener and MouseMotionListener in Java
- Java Program for Selection Sort
- Java Program for Bubble Sort
- Java Program for Insertion Sort
- Java Program for Heap Sort
- Java Program for Radix Sort
- Java Program for n-th Fibonacci numbers
- Java Program for Counting Sort
- Java Program for ShellSort
- Java Program for Longest Common Subsequence
- Java Program for Binary Search (Recursive and Iterative)

