From the course: Nail Your Java Interview

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Challenge: Generate binary numbers

Challenge: Generate binary numbers - Java Tutorial

From the course: Nail Your Java Interview

Start my 1-month free trial

Challenge: Generate binary numbers

(upbeat music) - [Narrator] It's time for a technical interview question. In this challenge, you will generate the first N binary numbers. Your algorithm will take in a number N as input and print out the first N binary numbers in numerical order. As a reminder, a binary number is a number that consists of zeros and ones and is on the base 2 numeral system. These are some examples of binary numbers. We start off with one, which maps to one in the binary system. Two maps to one zero. Three maps to one one. Four maps to one one zero and so on. Let's think about how this applies to our algorithm. If the input was six, your algorithm would print out one one zero, one one, one zero zero, one zero one, and one one zero. If the input is less than or equal to zero, the algorithm should print out nothing. For this challenge, consider looking for a pattern and using that pattern to generate future binary numbers.…

Contents