Friday, October 21, 2011

Binary Number

import java.io.*;
class Binary
{
    public static void main(String args[])throws IOException
    {
        InputStreamReader reader=new InputStreamReader(System.in);
        BufferedReader input=new BufferedReader(reader);
        System.out.println("PLEASE INPUT THE NUMBER");
        int n=Integer.parseInt(input.readLine());
        Binary(n);
    }
    public static void Binary(int n)
    {   
        int bin[]=new int[10];
        for(int j=9;j>=0;j--)
        {
            bin[j]=n%2;
            n=n/2;
        }
        for(int j=0;j<10;j++)
        System.out.print(bin[j]+"\t");
    }
}
       

No comments:

Post a Comment