我是一个初学者,我刚刚接触到静态方法,所以由于奇怪的控制流程,它们对我来说还是有点困惑。是什么导致了这里的错误?
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class GravityV1
{
public static double gravityCalculation(double[] planetMass, int[] planetDiameter)
{
double universalGravityConst = 6.67E-11;
double [] surfaceGravity = new double [planetMass.length];
for(int i = 0; i < planetMass.length; i++)
surfaceGravity[i] = ((universalGravityConst * planetMass[i]) / (Math.pow(planetDiameter[i] / 2, 2)));
return surfaceGravity;
}
public static void main(String [] args) throws IOException
{
String [] planets = {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"};
double [] mass = {3.3022E23, 4.8685E24, 5.97E24, 6.4185E23, 1.8986E27, 5.6846E26, 8.6810E25, 10.243E25};
int [] diameter = {4879, 12104, 12576, 6792, 142984, 120536, 51118, 49528};
double [] gravities = gravityCalculation(mass, diameter);
}
}