in JAVA by
Q:

How to convert decimal numbers to binary.

1 Answer

0 votes
by

Write a program to convert decimal numbers to binary.

import java.util.Scanner; 

class star 

public static void main(String arg[])    

{    

    Scanner sc=new Scanner(System.in); 

    System.out.println("Enter a decimal number"); 

    int n=sc.nextInt(); 

    int  bin[]=new int[100]; 

    int i = 0; 

    while(n > 0) 

    { 

    bin[i++] = n%2; 

       n = n/2; 

    } 

   System.out.print("Binary number is : "); 

    for(int j = i-1;j >= 0;j--) 

   { 

       System.out.print(bin[j]); 

   } 

Click here to read more about JAVA
Click here to read more about Insurance

Related questions

0 votes
asked Oct 24, 2020 in JAVA by sharadyadav1986
0 votes
asked Oct 23, 2020 in JAVA by rahuljain1
+1 vote
asked Feb 15 in Python by SakshiSharma
0 votes
asked May 17, 2020 in Python by sharadyadav1986
0 votes
asked Aug 1, 2020 in Matlab by Robindeniel
...