Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

Members have full access to the forums. Advertisements are removed for registered users.

# Thread: Java Static Method

1. ## 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

```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};

}
}```

2. ## Re: Java Static Method

get incompatibles type
Please post the full text of the error message that shows the source statement where the error happens.
`  for(int count = 0; count < 9;count++)`
You should the array's .length attribute to limit the looping, not a magic number:9

3. ## Re: Java Static Method

I fixed it on the post, thanks. ~Incompatibles type at return surfaceGravi;

4. ## 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

5. ## The Following User Says Thank You to Norm For This Useful Post:

maple1100 (January 3rd, 2013)

6. ## Re: Java Static Method

Oh, I didn't realize one is double and the other one is double array. Thanks you so much!