jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes paintComponent(page), Reverse digit, and Asterisks triangle outputter question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "paintComponent(page), Reverse digit, and Asterisks triangle outputter question" Watch "paintComponent(page), Reverse digit, and Asterisks triangle outputter question" New topic
Author

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

derek smythe
Ranch Hand

Joined: Apr 18, 2011
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
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
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

Joined: Apr 18, 2011
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

Joined: Apr 18, 2011
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: paintComponent(page), Reverse digit, and Asterisks triangle outputter question
 
Similar Threads
[Easy] Palindromes
Letter counter program. having trouble understanding it.
Stars program help
Separating the Digits in an Integer
Converting int to string W/OUT toString, etc.