Campbell Ritchie wrote:
Algorithm:Create empty String While i > 2 Find i % 2. Add that number to the left end of your String. Divide i by 2 in integer arithmetic End of while Display your String. Much better than the algorithm you had.
Campbell Ritchie wrote:I would still prefer a StringBuilder to using the + operator on Strings.
Sudhir Srinivasan wrote:Awaiting your response...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
John Jai wrote:and you are creating different StringBuilder objects in the loop.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Don't overthink this. You've got all the basic components there; you just need to put them in the right order. (Big Hint: try it by hand, and work out when you do the 'reverse' bit).
John Jai wrote:and you are creating different StringBuilder objects in the loop.
Campbell Ritchie wrote:If you use the insert() method of StringBuilder, and use index 0 throughout, you can get the binary output without needing to reverse anything.
Campbell Ritchie wrote:
I would still prefer a StringBuilder to using the + operator on Strings.
Campbell Ritchie wrote:I don’t think anybody will post a better explanation than what you have just shown. You can see how much effort you have put into it: well done
Campbell Ritchie wrote:
When you have ten minutes to spare, try this class:You can see how quickly the lines with a StringBuilder local variable are completed, and how much slower multiple += calls on a String are. You can time it with some System class methods.
I tried that program; I could see the delay after “Stringbuilder without size”, but not after “Stringbuilder with size”, because it was so fast. But “Using +=” has been sitting running for over 10 minutes and not completed.
Don’t worry; it will complete in under a weekSudhir Srinivasan wrote: . . . I'll certainly do as suggested and get back to you once I'm ready with my response.
regards,
Sudhir
Sudhir Srinivasan wrote:A more sophisticated explanation from you would help me understand better...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:Don’t worry; it will complete in under a week
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |