Thursday, June 19, 2014

Elementary Programming; Exercise No. 8

Average acceleration is defined as the change of velocity divided by the time taken to make the change, as shown in the following formula:
a = (v 1 - v 0)/t
Write a program that prompts the user to enter the starting velocity v0 in meters/second, the ending velocity  v1 in meters/second, and the time span t in seconds, and displays the average acceleration.

Solution:

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

   System.out.print("Enter the value of v0:");
   v0 = s.nextDouble();

   System.out.print("Enter the value of v1:");
   v1 = s.nextDouble();

   System.out.print("Enter the value of time:");
   time = s.nextDouble();

   acceleration = (v1 - v0) / time;

   System.out.print("The average acceleration is:" + acceleration);
}

No comments:

Post a Comment

Author