Question: Write a Java method with the following header: public static void binaryPrint(int n) The number n is non-negative. The method prints the value of n

Write a Java method with the following

header:

public static void binaryPrint(int n)

The number n is non-negative. The method prints

the value of n as a binary number. If n is zero, then

a single zero is printed; otherwise, no leading zeros

are printed in the output. The ' ' character is NOT

printed at the end of the output. Your implementation

must be recursive and not use any local variables.

EXAMPLES:

n=0 Output: 0

n=4 Output: 100

n=27 Output: 11011

note the following algorithm:

Binary Value 10110101 equivalent to Decimal value 181

181 divide by 2 equals 90 with remainder of 1

90 divide by 2 equals 45 with remainder of 0

45 divide by 2 equals 22 with remainder of 1

22 divide by 2 equals 11 with remainder of 0

11 divide by 2 equals 5 with remainder of 1

5 divide by 2 equals 2 with remainder of 1

2 divide by 2 equals 1 with remainder of 0

1 divide by 2 equals 0 with remainder of 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!