Part VI: Convert from a double WITHOUT A FRACTIONAL PART to a hexaicosadecimal string
Much like we did with the other method, we're going to start by solving this problem for the situation of a double that does not have a fractional part – that is, with nothing to the right of the decimal point – and get that working first. Only then (in the next section) will we proceed to solve the general problem of doubles with a fractional part.
The algorithm for doing this might look something like:
temp = the input double converted to an integer type
stringAccumulator = "
while (temp > 0)
currValue = the remainder when temp is divided by 26
c = currValue converted to the corresponding ASCII value
put c at the beginning of stringAccumulator
temp = the quotient when temp is divided by 26
return stringAccumulator
(NOTE: doubles can contain much bigger values than integer types like int or even long. For the purposes of Part V, you can assume that the value of your double safely fits within the integer type you are using.)
(NOTE on NOTE: To figure out the maximum value that a variable of a given type can take on, you can use the equivalent class. For example, there is a class Integer that provides convenience methods for working with ints, a class Double for working with doubles, a class Long for working with longs, and so on.
Integer: https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html
Double:https://docs.oracle.com/javase/8/docs/api/java/lang/Double.html
Long: https://docs.oracle.com/javase/8/docs/api/java/lang/Long.html
These classes have many useful methods for working with values of the associated types. For example, if you want to know the largest value that a variable of a given type can hold, you can access the CLASS_NAME.MAX_VALUE attribute - for example, Integer.MAX_VALUE)
Students succeed in their courses by connecting and communicating with an expert until they receive help on their questions
Consult our trusted tutors.