课程: Java Algorithms

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Queue algorithms: Generate binary numbers

Queue algorithms: Generate binary numbers - Java教程

课程: Java Algorithms

Queue algorithms: Generate binary numbers

- [Instructor] While the Java standard library has a built-in queue data structure with a few basic operations, you'll need to know how to leverage this functionality in order to work with your data efficiently. Let's say we want to create an algorithm that takes in a number N and prints out the first N binary numbers in numerical order. A binary number is a number that consists of ones and zeros and it's 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 and so on. The algorithm we create should generate as many of these numbers as we specify. If the input was five, the algorithm should print out one, one zero, one one, one zero zero and one zero one. If the input is less than or equal to zero, the algorithm should print out nothing. Now you might notice a pattern to these binary numbers. We print an item, in this case one, and then print the same item with…

内容