Java program to convert Decimal Number into Binary Number

This program will read Decimal number from the User and convert into its equivalent Binary Number in Java. It is an example of Decimal Number to Binary Number conversion in Java.

package com.includehelp;

import java.util.Scanner;

 * Program to convert given Decimal number to binary format
 * @author includehelp
public class DecimalToBinary {
    static String getBinaryNumber(int decimalNumber){
        StringBuilder binaryStr=new StringBuilder();
            int r           =decimalNumber%2;
            decimalNumber   =decimalNumber/2;
        return ( binaryStr.reverse().toString() ); 
    public static void main(String[] arg){
        Scanner sc  =   new Scanner(;
        System.out.print("Enter Decimal Number  : ");
        int decimalNumber =   sc.nextInt();
        String binaryNumber = getBinaryNumber(decimalNumber);
        System.out.println("Binary Number : "+binaryNumber);


Enter Decimal Number  : 566565
Binary Number : 10001010010100100101

Java Most Popular & Searched Programs »

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.