programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Liutauras Vilda
• Knute Snortum
• Bear Bibeault
Sheriffs:
• Devaka Cooray
• Jeanne Boyarsky
• Junilu Lacar
Saloon Keepers:
• Ron McLeod
• Stephan van Hulst
• Tim Moores
• Carey Brown
• salvin francis
Bartenders:
• Tim Holloway
• Piet Souris
• Frits Walraven

# paintComponent(page), Reverse digit, and Asterisks triangle outputter question

Ranch Hand
Posts: 63

for the star app. When it gets to line 3, row is 3 and star gets set back to 1, I don't understand how that happens. any help greatly appreciated. For the reverse digit app, I have tried both of these on paper and pencil , and I can't figure out how it works.

This post was previously posted on , java forum, but got no answer really..http://www.java-forums.org/new-java/44306-paintcomponent-page-reverse-digit-astericks-triangle-outputter-question.html#post209552

Rancher
Posts: 3656
34
• 1
The reason there was no good answers on the other forum is that the OP did not post correct code.
This posting compiles and executes correctly.

The number / 10 is a way to shift decimal digits one position to the right.
123 becomes 12. 12 becomes 1.

derek smythe
Ranch Hand
Posts: 63
Thank you Norm!! I will check out the answer. here is my explanation of the star code. It took me Forever to figure it out. GOD.

Each entry into the inner for loop resets "star" to one. So that on the 3rd outer loop, then inner, star is reset to 1, and "row' is set to 3, so then the inner loop runs three times, and prints out 3 stars on line 3. Then for the 4th outer loop, row is set to 4, go to inner star loop which is set to 1 again, and loop 4 times on that line. and so on. SWEET MAMA!

derek smythe
Ranch Hand
Posts: 63
Ok that just expanded my brain size by a few millimeters and I feel insane, but I understand the ReverseNumber app. Here is the wacky solution.

On the first iteration of the do while loop, lastDigit=4, then reverse=4, number = 123, then you output to screen reverse, which is 4.
Second iteration: lastDigit=3, reverse = 3, number= 12, and output of reverse is 3. Keep doing this until your first input of "1234", is output as "4321" Bing bang boom. Ta da! thank you to all my fans.

 Why is the word "abbreviation" so long? And this ad is so short? Java file APIs (DOC, XLS, PDF, and many more) https://products.aspose.com/total/java