Java Programs

Write a Java program to print number from decimal to binary


/*Java Program to print number from Decimal to Binary*/
public class DecimalToBinary {
    public static void main(String a[]){      
        int num = 5;  /*give required number here*/
        int binary[] = new int[25];
        int index = 0;
         while( num > 0){
             binary[index++] = num%2;
             num = num/2;
         }
         /* print in reverse order*/
         for(int i = index-1; i>=0; i--){
            System.out.print(binary[i]);
         }    
    }
}
www.000webhost.com