| 2 | import java.util.Scanner; |
| 3 | |
| 4 | public class BnaryCal { |
| 5 | public static void main(String[] args) { |
| 6 | Scanner scn = new Scanner(System.in); |
| 7 | int number = scn.nextInt(); |
| 8 | |
| 9 | calculateBinary(number, calculateLength(number)); |
| 10 | |
| 11 | } |
| 12 | |
| 13 | static int calculateLength(int n){ |
| 14 | int count =0; |
| 15 | while(n>0){ |
| 16 | n = n/2; |
| 17 | count++; |
| 18 | } |
| 19 | return count; |
| 20 | } |
| 21 | |
| 22 | static void calculateBinary(int n,int positions){ |
| 23 | // int count = 0; |
| 24 | // while(n>0){ |
| 25 | // n = n/2; |
| 26 | // count ++; |
| 27 | // } |
| 28 | int length = positions; |
| 29 | |
| 30 | int[] Binary = new int[length]; |
| 31 | int i =0; |
| 32 | while (n>0){ |
| 33 | Binary[i] = n%2; |
| 34 | n = n/2; |
| 35 | i++; |
| 36 | |
| 37 | } |
| 38 | for(int j= Binary.length-1; j>=0; j--){ |
| 39 | System.out.print(Binary[j]); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | |
| 44 | } |
nothing calls this directly
no outgoing calls
no test coverage detected