Computer Science, asked by Ashvi16, 1 year ago

WAP to accept a number and display the result in its binary equivalent.
for example-
input: 23
output: 10111
(in java)

Answers

Answered by QGP
4
import java.io.*;
public class Binary
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n,r;
        String d="";
 
       System.out.print("Enter a number: ");
        n = Integer.parseInt(in.readLine());
        while(n!=0)
        {
            r = n%2;
            d=Integer.toString(r)+d;
            n=n/2;
        }
         System.out.println("Binary equivalent is: "+d);
    }
}    
Answered by jebaqueen91
0

Answer:

IMPORTANT QUESTIONS FOR CLASS 10

Similar questions