In physics, a common useful equation for finding the position s of a body in linear motion at a given time t, based on its initial position , initial velocity , and rate of acceleration a, is the following:
Write code to declare variables for , , a, and t, and then write the code to compute s on the basis of these values.
Program:
public class Ch02Ex01
{
public static void main(String[] args)
{
double s0;
double v0;
double a;
double t;
double s;
s0 = 12.0;
v0 = 3.5;
a = 9.8;
t = 10.0;
s = s0 + (v0 * t) + (0.5 * a * t * t);
System.out.println("Initial position s0: " + s0);
System.out.println("Initial velocity v0: " + v0);
System.out.println("Given time t: " + t);
System.out.println("Rate of acceleration a: " + a);
System.out.println("Position s if a body in linear motion: " + s);
}
}
Output:
Initial position s0: 12.0
Initial velocity v0: 3.5
Given time t: 10.0
Rate of acceleration a: 9.8
Position s if a body in linear motion: 537.0