This week's book giveaway is in the Go forum.
We're giving away four copies of Head First Go and have Jay McGavren on-line!
See this thread for details.
Win a copy of Head First Go this week in the Go 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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
 
Rancher
Posts: 3353
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.
 
I just had the craziest dream. This tiny ad was in it.
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!