In this example we have a simple application that calls a number and convert it to binary using a recursive algorithm with an external variable.

The first thing we need to know is how to convert a number of base 10 a binary (base 2). To that end, the desired number is divided between 2 and each result of the division as many times as necessary until the number indivisible, 1. Then take the last result, 1 and the remains of all the divisions, watching the image will be much clearer concept.

We will now see the code in Java need to call the number on the back and base 10 in binary, of course you can add validations, in fact you have to add validation to ensure that the user enters a number, but that’s not the goal of this post.

In addition to the algorithm to convert the numbers, it’s worth seeing how it reads standard input, using a BufferedReader, but that’s what we will see in greater depth in another post.

### Also, you may be interested: