10. JAVA Program to find Mechanical Energy of a particle using E = mgh+1/2 mv2.
How does this program work?
- In this programme you will learn about how to calculate Mechanical Energy.
- This programme requires the user inputs Mass, displacement and velocity of the body.
- In First step it calculate Potential Energy and Kinetic Energy.
- This programme perform mathematical calculation and display the result using java.
Here is the code
// Mechanical Energy of a body
import java.util.Scanner;public class Particle
{
public static void main(String args[])
{
int m,h,v;
float k;
double e,p,g=9.8;
System.out.println("Enter Mass of the body \n");
Scanner obj1=new Scanner(System.in);;
m=obj1.nextInt();
System.out.println("Enter deplacement of body \n");
h=obj1.nextInt();
System.out.println("Enter velocity of the body ");
v=obj1.nextInt();
p=m*g*h;
// Potential Energy formula
System.out.println("Potential energy of the body :"+p);k=m*v*v/2;
//Kinetic Energy formula
System.out.println("kinetic energy of the body :"+k);e=p+k;
System.out.println("Mechanical energy of the body :"+e);
}
}