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.
01 | import java.util.Scanner; |
03 | public class Momentum { |
04 | public static void main(String [] args) { |
05 | Scanner in = new Scanner(System.in); |
07 | double velocity = 0.0 ; |
09 | System.out.print( "Enter object's mass in kilograms: " ); |
10 | mass = in.nextDouble(); |
12 | System.out.print( "Enter object's velocity in meter/second: " ); |
13 | velocity = in.nextDouble(); |
15 | System.out.println( "The momentum is: " + (mass * velocity)); |
Penulis : Unknown ~ Sebuah blog yang menyediakan berbagai macam informasi
0 comments:
Post a Comment