Friday, November 6, 2015

// // Leave a Comment

Java Physics Program To Calculate Average Acceleration

The program below is the answer to Liang's Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.9.

 * @Author: Aghatise Osazuwa
 * Website:
 * Exercise 2.9 - Physics: Acceleration

import java.util.Scanner;

public class PhysicsAcceleration {
    public static void main (String [] args) {

        Scanner input = new Scanner(;
        System.out.println("This Program Calculates Average Acceleration.\n");
        System.out.println("Enter starting velocity(v0) in meter/second: ");
        double startingVelocity = input.nextDouble();
        System.out.println("Enter ending velocity(v1) in meter/second: ");
        double endingVelocity = input.nextDouble();
        System.out.println("Enter time(t) in seconds: ");
        double time = input.nextDouble();
        double average = (endingVelocity - startingVelocity) / time;
        //display result to 4 decimal places
        System.out.println("The average acceleration is " + (int)(average * 10000) / 10000.0);

Click here to see other solutions to Introduction to Java Programming.


Post a Comment

DISCLAIMER: Opinions expressed in comments are those of the comment writers alone and does not reflect or represent the views of the post author. We reserve the right to delete any post deemed inappropriate or offensive and/or spammy. Please do not use abusive words/hate speech.

I Appreciate your valuable Feedback. So, Please DO NOT SPAM - Spam comments will be deleted immediately.

Don't use brand name in name field and you're not allowed to use links in comments unless it's necessary. Such comments will be removed immediately. To get notified of replies or follow-up comments, click the box next to notify me.