任务是编写输出程序
行星半径
行星的质量
逃逸速度
输入是周长和加速度。
[使用2个输入,我们将使用
如果我的输入是40075(地球周长),而9.8(加速度),我的输出半径是6378(正确),输出质量是5.97e18(正确的输出应该是5.97e24),我的输出逃逸速度是354(正确的输出是11184)。
这里是分配说明。
“使用下面的两个方程式(一个给定,一个在链接中)
equation 1:
a=(G*m)/(r^2)
和
等式2:请参见下面的链接
http://www.softschools.com/formulas/physics/escape_velocity_formula/90/
G是一个常数(找到它)
向用户询问周长,以公里为单位
问由于重力引起的加速度,单位为m / s ^ 2
输出:
包括单位和格式”
这是我的程序代码。
import java.util.*;
import java.lang.Math;
class Main {
public static void main(String[] args) {
Scanner userInput = new Scanner (System.in);
System.out.println("\nWelcome to the Escape Velocity Application. To begin, please enter the following information below. \nEnter the circumference (km):");
double circum = userInput.nextDouble();
System.out.println("Enter the acceleration due to gravity (m/s^2):");
double a = userInput.nextDouble();
//Gravitational constant
double G = 6.67408e-11;
//Radius
double r = Math.round((circum/2)/Math.PI);
//Mass
double m = Math.round((a*(Math.pow(r,2)))/G);
//Escape Velocity
double e = Math.round(Math.sqrt((2*G*m)/r));
System.out.println("\nThe radius is: "+r+" kilometers.");
System.out.println("\nThe mass is: "+m+" kg.");
System.out.println("\nThe escape velocity is: "+e+" m/s.");
}
}
经典物理学错误!在物理学中使用任何公式时,请确保使用正确的单位。
您可以接受以千米为单位的天体周长的输入,但请确保在计算过程中将其转换为米。记住:x km = x *10^3m
double circum = 40075 * Math.pow(10, 3); // convert km to m
double f = 9.807; //more accurate
double G = 6.67408e-11;
double r = circum/(2*Math.PI);
double m = f*Math.pow(r, 2)/G;
double e = (Math.sqrt((2.0*G*(m))/r));
System.out.println("The radius is: " + r * Math.pow(10, -3) + " kilometers.");
System.out.println("The mass is: " + m + " kg.");
System.out.println("The escape velocity is: " + e + " m/s.");
此代码提供输出:
The radius is: 6378.134344407706 kilometers.
The mass is: 5.981328662579845E24 kg.
The escape velocity is: 11184.843630163667 m/s.
我所做的只是将km转换为m,并将f转换为更准确的值。