Calculate The Momentum Of An Object In Java

[postlink]https://iamdaowner.blogspot.com/2012/06/calculate-momentum-of-object-in-java.html[/postlink]
 An object's momentum is its mass multiplied by its velocity. Write a program that expects an object's mass (in kilograms) and velocity ( in meters per second) as inputs and prints its momentum.

This program used Scanner method for getting user's input. Save this file as Momentum.java.

01import java.util.Scanner;
02 
03public class Momentum {
04  public static void main(String [] args) {
05    Scanner in      = new Scanner(System.in);
06    double mass     = 0.0;
07    double velocity = 0.0;
08 
09    System.out.print("Enter object's mass in kilograms: ");
10    mass = in.nextDouble();
11 
12    System.out.print("Enter object's velocity in meter/second: ");
13    velocity = in.nextDouble();
14 
15    System.out.println("The momentum is: " + (mass * velocity));
16 
17 }
18}

0 comments:

Post a Comment

Grab the widget  IWeb Gator
Powered by Blogger.

Click the Like Button Below To Receive all updates via Facebook

Powered By Blogger Tricks |

Popular Posts