Java Examples
Java ExamplesPrograms with output

Java Program to Convert Decimal to Binary


Example:
import java.util.Scanner;

public class DecimalToBinary
{
    public static void main(String args[])
    {
        int decnum, rem, quot, i=1, j;
        int binnum[] = new int[100];
        Scanner scan = new Scanner(System.in);
		
        System.out.print("Enter Decimal Number: ");
        decnum = scan.nextInt();
		
        quot = decnum;
		
        while(quot != 0)
        {
            binnum[i++] = quot%2;
            quot = quot/2;
        }
		
        System.out.print("Binary Value of " + decnum + " is ");
        for(j=i-1; j>0; j--)
        {
            System.out.print(binnum[j]);
        }
    }
}
Output:
Enter Decimal Number: 
123 
Binary Value of 123 is 1111011

Share this page on:

Was this page helpful ?

Let us know how we did!

Subscribe Email Updates

to get latest update