binary code code java

Solutions on MaxInterview for binary code code java by the best coders in the world

showing results for - "binary code code java"
Christian
04 Sep 2016
1class DecimalBinaryExample{
2 
3  public void convertBinary(int num){
4     int binary[] = new int[40];
5     int index = 0;
6     while(num > 0){
7       binary[index++] = num%2;
8       num = num/2;
9     }
10     for(int i = index-1;i >= 0;i--){
11       System.out.print(binary[i]);
12     }
13  }
14 
15  public static void main(String a[]){
16     DecimalBinaryExample obj = new DecimalBinaryExample();
17     System.out.println("Binary representation of 124: ");
18     obj.convertBinary(124);
19     System.out.println("\nBinary representation of 45: ");
20     obj.convertBinary(45);
21     System.out.println("\nBinary representation of 999: ");
22     obj.convertBinary(999);
23  }
24}