任务是编写一个输出的程序
radius
输入是圆周和加速度。
对于这两个输入,我们将使用
如果输入为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.");
}
}发布于 2019-10-14 19:30:44
经典的物理错误!当你在物理中使用任何公式时,确保你使用的是正确的单位。
你可以接受以公里为单位的天体周长的输入,但要确保在计算过程中把它转换成米。记住: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.我所改变的就是把公里转换成m,把f转换成一个更精确的值。此外,请记住,在完成最后的计算之前不要舍入,这将保持最大的准确性。
https://stackoverflow.com/questions/58382864
复制相似问题