我需要在一行中编写数组并通过几个不同的类进行传递。到目前为止,这是我的代码。我将如何使阵列全球化?我很困扰。这就是我通过在线课程学习的方式。公共类 GravityV1 {
String[] planet= {"Mercury", "Venus","Earth","Mars", "Jupiter", "Saturn", "Uranus","Pluto"};
int[] diameter = { 4876, 12107, 12755, 6794, 142983, 120536, 51117, 49527, 2390};
double[] mass= { 3.30e23,4.87e24,5.97e24,6.42e23,1.90e27,5.69e26, 8.66e25, 1.03e26, 1.31e22};
public double calcgravity(double g, double r, double m)
{
g=(6.67e-11*m)/r;
return g;
}
public static void printdata()
{
System.out.println ("Planetary Data");
System.out.println("Planet");
System.out.printf("%8s", "Diameter (Km)");
System.out.printf("%8s", "Mass (Kg)");
System.out.printf("%10s", "g(ms^-2)");
System.out.println("----------------------------------------------------------------------------------------------------------------------------------");
for (int index=0; index<9; index++)
{System.out.println( planet[index]);
System.out.printf("%8f", diameter[index]);
System.out.printf("%8f", mass[index]);
}
}
public static void main(String[] args)
{
}
}