Question: In Java, Consider the following general algorithm for converting a decimal number to binary: String s is an empty string Iteration (while number is greater
In Java, Consider the following general algorithm for converting a decimal number to binary:
String s is an empty string
Iteration (while number is greater than zero)
Determine the integer remainder of number / 2
Append to s the remainder
Replace the number with number / 2
End the iteration
If you try this using 13 as your decimal number youll get an answer of 1011 which is not correct. 13 in binary is actually 1101. Write a proper Java method that uses a stack so that the result is correct. Assume you have access to either an integer or generic stack as described by the assignments. Do not simply use the stack superficially, you must integrate it into the algorithm. State any assumptions you are making.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
