### Java Program to Convert Decimal to Binary - The Coding Shala

Home >> Java Programs >> Convert Decimal to Binary Hey there, welcome back to another post. In this post, we will learn how to convert decimal to binary in Java. Java Program to Convert Decimal to Binary You have given a decimal number. Write a Java program to convert decimal to binary. Example 1: Input: 7 Output: 111 Input: 10 Output: 1010 Decimal to Binary Conversion using Array Approach To convert decimal to binary we can follow the below steps: Store the remainder in the array when we divide the number by 2. Divide the number by 2. Follow the above two steps until the number is above 0. Print the array in reverse order. For example: 4 % 2 = 0 => 4/2 = 2 2 % 2 = 0 => 2/2 = 1 1 % 2 = 1 => 1/2 = 0 Binary of 4 is: 100 Java Program: import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * https://www.thecodingshala.com/ */ public class Main { public static void printBinary( int num) {