• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
derek smythe
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Norm Radder
Bartender
Posts: 1241
14
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic