【发布时间】:2020-02-11 10:30:14
【问题描述】:
任务是编写一个输出的程序
行星半径
行星的质量
逃逸速度
输入是周长和加速度。
有了 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
输出:
- 以千米为单位的行星半径
- 以 kg 为单位的行星质量(使用公式 1)
- 以 km/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.");
}
}
【问题讨论】:
-
double r = Math.round((circum/2)/Math.PI);应该是double r = Math.round((circum/2.0)/Math.PI);