Go to Top

Tuesday, 17 January 2012

To convert decimal number into binary notation

Question 73 : Write a program in Java to convert a decimal number into binary notation.

Java Program : 

class dectobin
{
 static void main(int m)
 {
     String s="";
     int n=m;
     while(n>0)
     {
         s=String.valueOf(n%2)+s;
         n=n/2;
        }
        System.out.print("The binary value of "+m+" is : "+s);
    }
}

ShareThis