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?
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:
Never ascribe to malice that which can be adequately explained by stupidity.
David Barry
Ranch Hand
Joined: Jan 13, 2009
Posts: 83
posted
0
Thanks for shedding some insight onto my problem. I am continuing to work on it. Thanks