(int n,int positions)
| 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 | } |