Share on Google+Share on Google+

Abhishek Sisodia
Java program?
2 Answer(s)      7 years ago
Posted in : Java Beginners
In order for an object to escape planet's gravitational pull, it must attain a minimum initial velocity called the escape velocity. The escape velocity varies from planet to planet.Create a Java program which calculates the escape velocity for the planet. Your program should first prompt the user for the circumference of the planet and then the acceleration due to gravity on the planet. From this information you determine the radius, mass, and escape velocity of the planet using the following equations:
vescape = square root(2 *G*m/r); g = G m/r^2; G = 6.67x10-11 Nm^2/kg^2.
The console output should look similar to:

Circumference of planet, km? 38000
Acceleration due to gravity, m/s2? 9.8

Calculating the escape velocity?
Planet radius: 6047.9 km
Planet mass: 5372.0 x 10^21 kg
Escape velocity: 10.9 km/s;

***********************This is my code so far******************
import java.util.Scanner;

class EscapeVelocity
public static void main( String[] args)
double circum;
double accel;

System.out.print("What is the circumference of the planet in km? ");
Scanner scanner= new Scanner(;
circum = scanner.nextDouble();
System.out.print("What is the acceleration due to gravity in m/s^2? ");
scanner= new Scanner(;
accel = scanner.nextDouble();

System.out.println("Calculating the escape velocity...");
final double PI = 3.14159;// constant value declared
double radius = circum/(2*PI);
System.out.println("Planet Radius: "+ radius+" km");
final double G= 0.0000000000667 ;
double mass = accel*Math.pow(radius,2)/G;
System.out.println("Planet mass: "+ mass+ " kg");
double vescape= Math.sqrt(2*G*mass/radius);
System.out.println("Escape Velocity: "+ vescape+ " km/s");

Please suggest modifications to get the exact ans. as in the question.
I also think the last double vescape formula is getting me the wrong ans. so please help


View Answers

February 26, 2010 at 1:41 AM

Hi Abhishek Sisodia,

There is no flaw in your coding. Every thing is perfect.
Only mistake you are doing is giving the wrong i/p.

Here you are calculating escape velocity for planet Earth and you are performing all the calculations in km/s. But,you are giving Acceleration due to gravity 'g' in m/s.

Just give its value in km/s i.e 0.0098

You would get the answer you are expecting.

Just FYI,
These are the accurate values:
Circumference of Earth : 40,075.16 kms
Acceleration due to gravity (g) : 0.0098 km/s
Radius of the earth : 6,371 kms
Mass of the earth : 5.9742E24 kgs
G : 6.673006E-11
Escape Velocity of Earth : 11.1 km/s

Here are the links that I reffered:

It took me 4 hrs, to figure this out :)



February 26, 2010 at 7:31 AM

thank you very much javaquest

Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code


Advertisement null