Decimal to Binary Number in JAVA

Decimal to Binary Number


Example : Input : 13
                  Output : 1101
 

Program given Below :-

The video link of this program is provided at the end of this post.
Program :-

import java.io.*;
import java.util.*;
class Binary
{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
        int n,p,a;
        String str="";
        System.out.println("Enter Number to Convert it into Binary");
        n= in.nextInt();
        p=n;
        while(p>0)
        {
            a=p%2;
            str=a+str;
            p=p/2;
        }
        System.out.println("Original Number : "+n);
        System.out.println("Binary Form : "+str);
    }
};
            


All the best :)

Watch this Program Video : https://youtu.be/BvyK9kyULig

Comments

Popular posts from this blog

Frequency of each digit of a number in Java

Trimorphic Number in JAVA

Tri-Automorphic Number in JAVA