Ok. this is my first tutorial so i hope that you will understand.
How this programme works:

  • Input – decimal number
  • output – binary number


So here is code:


import java.util.*;
public class number{

        public static void main (String [] args)

        {

                Scanner input = new Scanner (System.in);

                System.out.println ("Input decimal number");

                int decimal = input.nextInt ();

                input.close ();

               

                int base = 2;

                int result = 0;

                int multiplier = 1;

               

                while (decimal>0)

                {

                        int residue = decimal%base;

                        decimal = decimal/base;

                        result = result +residue*multiplier;

                        multiplier = multiplier * 10;

                }

                System.out.println ("binary....."+result);

        }
}

 

What Do You Think on This ? Say Here

This site uses Akismet to reduce spam. Learn how your comment data is processed.