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);
    }
}

4 comments:

  1. i want that if i write a normal program in blue j and i want to convert it into a application (like printing factors of no.)then how do i convert it into a application

    ReplyDelete
    Replies
    1. Actually, BlueJ doesn't allow creation of applications as such. But I have a few alternatives :

      1) The easiest is to learn to create an applet in Java. Applet is just like an application, but it runs only on a server(or a browser window). For an example, visit the link below :

      http://icse-java.blogspot.com/2011/09/applet-4-change-background.html
      http://icse-java.blogspot.com/2011/09/applet-3-colour-change_11.html

      2) You can try to use the byte code generated by Java to be run by others in a Java Virtual Machine. I don't have much information on this one, you may try to get a little help from Google. I have had tried this, but without any good results. I will keep trying to solve your problem.

      Delete
    2. And yes, you might also create a .jar file from BlueJ -> Project -> Create Jar File. But this doesn't work for our program. Still give it a try.

      Delete

ShareThis