Computer Science, asked by ganeshkella, 1 year ago

write a java program to convert number from binary to decimal

Answers

Answered by yogesh2907
0
Java program is a program which we have to convert into from binary to decimal

ganeshkella: hey nuvu won rupee
Answered by Anonymous
1

import java.util.*;

class DtoB

{

   int dec;

   String B;

   DtoB(int dec1)

   {

       dec=dec1;

       B="";

   }

   String Bin()

   {

       int r=1;

       int d=0;

       B="";

       while(dec!=1)

       {

           r=dec%2;

           B=r+B;

           dec=dec/2;

       }

       return 1+""+B;

   }

   public static void main(String args[])

   {

       Scanner sc=new Scanner(System.in);

       System.out.println("Enter the number in decimal system . Please enter an integer.");

       int dec1=sc.nextInt();

       DtoB d=new DtoB(dec1);

       String str=d.Bin();

       System.out.println("The converted decimal to binary system is "+str);

   }

}

Similar questions