Program to calculate Kinetic Energy and Potential Energy | Java program to implement the above approach ; Function to calculate Kinetic Energy ; Stores the Kinetic Energy ; Function to calculate Potential Energy ; Stores the Potential Energy ; Driver Code
class GFG { static double kineticEnergy ( double M , double V ) { double KineticEnergy ; KineticEnergy = 0.5 * M * V * V ; return KineticEnergy ; } static double potentialEnergy ( double M , double H ) { double PotentialEnergy ; PotentialEnergy = M * 9.8 * H ; return PotentialEnergy ; } public static void main ( String [ ] args ) { double M = 5.5 , H = 23.5 , V = 10.5 ; System . out . println ( " Kinetic ▁ Energy ▁ = ▁ " + kineticEnergy ( M , V ) ) ; System . out . println ( " Potential ▁ Energy ▁ = ▁ " + potentialEnergy ( M , H ) ) ; } }