Java solution to convert decimal to a given base using recursion
Not what you're looking for?
Dear OTA -
I need 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
Purchase this Solution
Solution Summary
A Java solution to convert decimals to a given base using recursion is examined.
Purchase this Solution
Free BrainMass Quizzes
Java loops
This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.
Basic Networking Questions
This quiz consists of some basic networking questions.
Basic Computer Terms
We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.
Javscript Basics
Quiz on basics of javascript programming language.
Word 2010: Tables
Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.