Decimal to binary conversion in java

Java code to convert decimal number into binary number 


import java.io.*;

class Test {
    public static void main(String[] args) throws IOException {
    long n,m,no=0l,a=1,rem;
    System.out.println("Enter the decimal number");
    BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
    n=Integer.parseInt(br.readLine());
    m=n;
    while(n!=0){
          rem=n%2;
          no=no+rem*a;
          n=n/2;
          a=a*10;
    }
    System.out.println("The value "+m+" in binary is"+no);
    }

No comments: