Forums Register Login

Trouble with a static method

+Pie Number of slices to send: Send
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?

+Pie Number of slices to send: Send




Use double array for surfaceGravity like you used for others. And index with surfaceGravity[y] to store individually for each y.
+Pie Number of slices to send: Send
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:


+Pie Number of slices to send: Send
Thanks for shedding some insight onto my problem. I am continuing to work on it. Thanks
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


Reply locked
This thread has been viewed 1286 times.
Similar Threads
Need help with static methods.
about enum
Need help writing a text file
Enum problem/error
Displaying the largest and smallest of three integers
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:17:13.