Create a java solution read a decimal integer


Discuss teh below:

Q: Create a Java solution that can read a decimal integer and convert it to binary or any other given base system using recursion. For example, the Java program will do as follows:

read a decimal Integer, val, until "q" is read

if "q" then stop

else read another Integer, base, which will be a representation base

call a method, Converting (val, base), recursively

Note that the method Converting (a,b) will do recursively:
Converting (a,b)
if a is dividable by b
compute the remainder r and the quotient q
call the method Converting (q,b)
print r
else print a

The sample run should look as follows:

Enter an Integer or 'q' to quit:
8
An Integer for the representation base:
2
The given number 8 is converted to 1000 in the base 2 representation.
Enter an Integer or 'q' to quit:
21
An Integer for the representation base:
5
The given number 21 is converted to 41 in the base 5 representation.
Enter an Integer or 'q' to quit:
21
An Integer for the representation base:
7
The given number 21 is converted to 30 in the base 7 representation.
Enter an Integer or 'q' to quit:
21
An Integer for the representation base:
8
The given number 21 is converted to 25 in the base 8 representation.
Enter an Integer or 'q' to quit:
21
An Integer for the representation base:
9
The given number 21 is converted to 23 in the base 9 representation.
Enter an Integer or 'q' to quit:
q

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Create a java solution read a decimal integer
Reference No:- TGS01934880

Now Priced at $25 (50% Discount)

Recommended (98%)

Rated (4.3/5)