Thursday, June 19, 2014

Elementary Programming; Exercise No. 10

Given an airplane’s acceleration a and take-off speed v, you can compute the minimum runway length needed for an airplane to take off using the following formula:
length = v2/(2*a)
Write a program that prompts the user to enter v in meters/second (m/s) and the acceleration a in meters/second squared (m/s 2 ), and displays the minimum runway length.

Solution:

public static void main(String[] args) {
   Scanner s = new Scanner(System.in);
   double acceleration, speed, length;

   System.out.print("Enter speed:");
   speed = s.nextDouble();

   System.out.print("Enter acceleration:");
   acceleration = s.nextDouble();

   length = (Math.pow(speed, 2))/(2*acceleration);

   System.out.print("The minimum runway length for this airplane is " + length);
}

No comments:

Post a Comment

Author