0
當我嘗試使用gravity2方法時,我得到零輸出,但我仍然不完全知道分離方法如何幫助,因爲我是新手,接觸不同方法的規則。我怎樣才能打電話給方法打印q[]
?我的輸出結果爲零
public class Gravity
{
public static double[] gravity(double[] radius, double[] z, double[] radius1)
{
for (int index = 0; index < radius.length; index++)
{
z[index] = radius[index] * radius1[index];
}
return z;
}
public static double[] gravity2(double[] q, double[] masses, double[] z)
{
for (int index = 0; index < masses.length; index++)
{
q[index] = (z[index] * 6.67E-11)/masses[index];
}
return z;
}
public static void printResults(String[] names, double[] z, String[] m, double[] q) throws IOException
{
System.out.println(" Plantetary Data");
System.out.println("=====================================");
System.out.println("Planet Diameter Mass Gravity");
for (int index = 0; index < names.length; index++)
{
System.out.printf("%1s ", names[index]);
System.out.printf("%7.1f", z[index]);
System.out.printf("%10s", m[index]);
System.out.printf("%6.1f", q[index]);
System.out.printf("%n");
}
}
public static void main(String[] args) throws IOException
{
// Initialize variables
String[] names =
{
"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"
};
double[] radius =
{
2439.7, 6051.9, 6378, 3402.5, 71492, 60270, 25562, 24774, 1195
};
double[] masses =
{
3.3022 * Math.pow(10, 23), 4.8685 * Math.pow(10, 24), 5.9736 * Math.pow(10, 24), 6.4185 * Math.pow(10, 23), 1.8986 * Math.pow(10, 27), 5.6846 * Math.pow(10, 26), 8.6810 * Math.pow(10, 25), 1.0243 * Math.pow(10, 26), 1.312 * Math.pow(10, 22)
};
8.68E+25
, 1.02E+26, 1.27E+22}; // See IMACS double lesson for big E notation
double[] radius1 =
{
2439.7, 6051.9, 6378, 3402.5, 71492, 60270, 25562, 24774, 1195
};
double z[] = new double[10];
double q[] = new double[10];
String m[] =
{
"3.30E+23", "4.87E+24", "5.97E+24", "6.42E+23", "1.90E+27", " 5.68E+26", " 8.68E+25", "1.02E+26", " 1.27E+22"
};
// Processing
double gravities1[] = gravity(radius, z, radius1);
double gravities2[] = gravity2(q, masses, z);
// Output
printResults(names, z, m, q);
printToFile(gravities1);
printToFile(gravities2);
}
是您的代碼中模擬兩個合成的元素之間的熱核反應? –
@ Trojan.ZBOT它正在解決行星之間的重量差異 – FlyingKalamari
你的代碼中缺少一些東西。在數組'質量'和'半徑1'之間數字不與任何東西連接。 – Pawel