The program below is the answer to Liang’s Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.9.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> * Exercise 2.9 - Physics: Acceleration<br /> *<br /> */ <br /><br />import java.util.Scanner;<br /><br />public class PhysicsAcceleration {<br /> public static void main (String [] args) {<br /><br /> Scanner input = new Scanner(System.in);<br /> <br /> System.out.println("This Program Calculates Average Acceleration.n");<br /> <br /> System.out.println("Enter starting velocity(v0) in meter/second: ");<br /> double startingVelocity = input.nextDouble();<br /> <br /> System.out.println("Enter ending velocity(v1) in meter/second: ");<br /> double endingVelocity = input.nextDouble();<br /> <br /> System.out.println("Enter time(t) in seconds: ");<br /> double time = input.nextDouble();<br /> <br /> double average = (endingVelocity - startingVelocity) / time;<br /> <br /> //display result to 4 decimal places<br /> System.out.println("The average acceleration is " + (int)(average * 10000) / 10000.0);<br /> }<br />}<br /> |
Click here to see other solutions to Introduction to Java Programming.