首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调试我的逃逸速度程序中的问题

调试我的逃逸速度程序中的问题
EN

Stack Overflow用户
提问于 2019-10-14 19:18:22
回答 1查看 377关注 0票数 1

任务是编写一个输出的程序

radius

  • planet's
  • 行星的质量
  • 逃逸速度

输入是圆周和加速度。

对于这两个输入,我们将使用

  • Acceleration由于重力方程计算质量

  • 逃逸速度公式来计算逃逸速度。

如果输入为40075 (地球周长)和9.8 (加速度),则输出半径为6378 (正确),输出质量为5.97e18 (正确输出应为5.97e24),输出逃逸速度为354 (正确输出为11184)。

这是作业说明。

“使用下面的两个方程(一个给定,一个在链接中)

代码语言:javascript
复制
equation 1:
a=(G*m)/(r^2)

等式2:请参阅下面的链接

http://www.softschools.com/formulas/physics/escape_velocity_formula/90/

G是一个常数(找到它)

询问用户以公里为单位的周长。

求m/s^2中重力引起的加速度。

输出:

  1. 行星半径在km
  2. 行星质量中(使用方程1)
  3. 逃逸速度(使用方程2)

包括单位和格式“

这是我的程序代码。

代码语言:javascript
复制
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.");

  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-14 19:30:44

经典的物理错误!当你在物理中使用任何公式时,确保你使用的是正确的单位。

你可以接受以公里为单位的天体周长的输入,但要确保在计算过程中把它转换成米。记住:x km = x *10^3m

代码语言:javascript
复制
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.");

此代码给出了输出:

代码语言:javascript
复制
The radius is: 6378.134344407706 kilometers.

The mass is: 5.981328662579845E24 kg.

The escape velocity is: 11184.843630163667 m/s.

我所改变的就是把公里转换成m,把f转换成一个更精确的值。此外,请记住,在完成最后的计算之前不要舍入,这将保持最大的准确性。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58382864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档