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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started