This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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

 
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
 
Master Rancher
Posts: 3272
33
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!