This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
    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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Trouble with a static method  RSS feed

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Report post to moderator
I am trying to write a program that calculates the surface gravity on each planet in our solar system. I have the printing of the results assigned to a static method. However, I have a problem. There are two for statements I am using in this program. The last for statement is causing me trouble. It calls back up the printResults static method to use in the main method. However, on the last variable, which is surfaceGravity, the program is not printing out all of the values of surfaceGravity. It is just printing out the last one. How should I get it to print out all of the surfaceGravity values? Can somebody help me with this?

 
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator




Use double array for surfaceGravity like you used for others. And index with surfaceGravity[y] to store individually for each y.
 
lowercase baba
Bartender
Posts: 12627
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
surfaceGravity is declared as an int - which means it can only hold one value. Each time you go through your first loop, you over-write the previous value with the one you compute.

If you want to save all of them, you need an array, just like you store all your other values. Your other option would be to do something like this:


 
David Barry
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thanks for shedding some insight onto my problem. I am continuing to work on it. Thanks
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!