0% found this document useful (0 votes)
29 views1 page

SUPWprjct

The code accepts a decimal number from the user, converts it to binary and prints the binary number. It uses a for loop to repeatedly divide the number by 2 and calculate the remainder to extract the bits, which are multiplied by powers of 10 and added to get the binary number in decimal form.

Uploaded by

Nakul Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views1 page

SUPWprjct

The code accepts a decimal number from the user, converts it to binary and prints the binary number. It uses a for loop to repeatedly divide the number by 2 and calculate the remainder to extract the bits, which are multiplied by powers of 10 and added to get the binary number in decimal form.

Uploaded by

Nakul Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

*;
class conversiontobinarynos
{
public static void main()
{
Scanner kb= new Scanner(System.in);
System.out.println("Enter any whole no.");
int a=kb.nextInt(); int b=0;
for(int e=a,i=1; e>0;b=b+(e%2)*i,e=e/2,i=i*10)
System.out.println(b);
}
}

You might also like