# Java Static Method

• January 3rd, 2013, 07:51 PM
maple1100
Java Static Method
Could someone give me a hints on how I can return the answer to "surfaceGravi" I get incompatibles type when I try to return it to surfaceGravi. Thanks

Code :

```public class GravityV1 { // Calculate surface gravity public static double surfaceGrav( double []massKilo, double[] diameter) { double gravConstant = 6.67E-11; double []surfaceGravi= new double[9]; for(int count = 0; count < surfaceGravi.length;count++) { surfaceGravi[count] = ((gravConstant * massKilo[count]) / (Math.pow(diameter[count]/2,2))); } return surfaceGravi; }   public static void main(String[]args) { String [] planetName = {"Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune","Pluto"}; double [] massKilo = {3.30E23,4.869E24,5.972E24,6.4219E23,1.900E27,5.68E26,8.683E25,1.0247E26,1.27E22}; double [] diameter = {4880,12103.6,12756.3,6794,142984,120536,51118,49532,2274};   } }```
• January 3rd, 2013, 07:52 PM
Norm
Re: Java Static Method
Quote:

get incompatibles type
Please post the full text of the error message that shows the source statement where the error happens.
Code :

` for(int count = 0; count < 9;count++)`
You should the array's .length attribute to limit the looping, not a magic number:9
• January 3rd, 2013, 07:58 PM
maple1100
Re: Java Static Method
I fixed it on the post, thanks. ~Incompatibles type at return surfaceGravi;
• January 3rd, 2013, 08:01 PM
Norm
Re: Java Static Method
What data type is the method defined to return?
What data type is surfaceGravi?
If they are not the same or compatible, then you need to change one or the other:
Either Define the method to return surfaceGravi's type
Or Return a value of the correct type
• January 3rd, 2013, 08:09 PM
maple1100
Re: Java Static Method
Oh, I didn't realize one is double and the other one is double array. Thanks you so much!