Java program?



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



Advertisement null