java - What might be causing my results to print out in reverse of what they should? -
For this set of my last experiment I have do / while-while loops and I'm different from this one side My result is printed in this exact reverse how it should be.
Public category classesAnini {Private int base 10; Private In Newbes; Public Tenanto () {} Public Tantawany (integer ten, in base) {base 10 = ten; NewBase = base; } Public Zero Saturns (integer ten, inti base) {base10 = ten; NewBase = base; } Public string getNewNum () {string newNum = ""; Int orig = base10; While (original> gt; 0) {newNum = orig% newBase + newNum; Orig = origin / newBase; } Return new number; } Public string toring () {string full = base 10 + "base is 10" + receivedNew () + "in base" + newbase; Return complete; }} Here are my outcomes:
234 base 10 base 9 280
100 base 10 1100100 is the base 2 in
These are the expected results for the first two values (23 in the base 9 and 100 in the binary)
What I'm doing here:
234 Base 10 is 08 in base 9
100 base 10 base 2 in 0010011
You're adding an end to newNum instead of prepending. newNum = newNum + orig% newBase; ... should be ... newNum = orig% newBase + newNum; For characters ...
When orig% newBase & gt; 9 , then char (55 + orig% newBase) var nextValue = orig% newBase; If (Next value> 9) {newNum = char (55 + Next value) + newNum; } Else {newNum = nextValue + newNum; }
Comments
Post a Comment