Question: Create a recursive program that takes a decimal number and returns that number in binary. Some Hints are after the photo. Reminder on how to
Create a recursive program that takes a decimal number and returns that number in binary.
Some Hints are after the photo.
Reminder on how to convert decimal to binary:
Hint: remember the three steps. 1. how to simplify 2. how to get to the answer to main problem if I have the answer to the simplified version 3. what is the base case.
From the photo above, you see that simplification is /2 (you're welcome) now think about how knowing the binary representation of 78 you can get to binary representation of 156 (or 157), and then think of the base case.
package Recursion_Binary;
public class DriverD2B {
public static void main(String args[])
{
System.out.println(FindBinary.find(10));
System.out.println(FindBinary.find(12));
System.out.println(FindBinary.find(100));
System.out.println(FindBinary.find(13));
}
}
package Recursion_Binary;
public class FindBinary {
// Decimal to binary conversion
// using recursion
static int find(int decimal_number){
/*
* Your Codes Here
*/
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
