logo Practice-It logo

printBinary

Language/Type: Java recursion
Author: Marty Stepp (on 2020/11/05)

Write a recursive method called printBinary that takes an integer n as a parameter and that counts in binary using n digits, printing each value on a separate line. All n digits should be shown for all numbers. For example, if n is 2, the output should be:

        00
        01
        10
        11

When n is equal to 3, the output should be:

        000
        001
        010
        011
        100
        101
        110
        111

Your method should throw an IllegalArgumentException if n is less than 0 and should produce no output if n is equal to 0.

Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.