# Calculate energy to heat water in Java …ftc

Write a program that calculates the energy needed to heat water from an initial temperature to a final temperature.

Your program should prompt the user to enter the amount of water in kilograms and the initial and final temperatures of the water.

The formula to compute the energy is Q = M * (final_Temperature – initial_Temperature) * 4184

Where M is the weight of water in kilograms, temperatures are in degrees Celsius, and energy Q is measured in joules.

Use Double Data Type

``````Input:
Mass of water = 340
Initial temp = 12
Final temp = 90

Output:
The energy needed is =  1.109597``````
```import java.util.*;
import java.lang.*;
public class temp{
public static void main(String[] args){
double M,Q,final_temp,initial_temp;
Scanner scan = new Scanner(System.in);

System.out.print("Enter the mass of water:  ");
M = scan.nextDouble();
System.out.print("Initial Temperature:  ");
initial_temp = scan.nextDouble();
System.out.print("Final Temperature:  ");
final_temp = scan.nextDouble();

Q = M*(final_temp-initial_temp)*4184;
System.out.println(String.format("The energy needed is =  %f",Q/Math.pow(10,8)));
}
}
```

INPUT_1:
Enter the mass of water:  340
Initial Temperature:  12
Final Temperature:  90

OUTPUT:
The energy needed is = 1.109597

INPUT_2:
Enter the mass of water:  500
Initial Temperature:  12
Final Temperature:  34

OUTPUT:
The energy needed is = 0.460240

INPUT_3:
Enter the mass of water:  1000
Initial Temperature:  10
Final Temperature:  100

OUTPUT:
The energy needed is = 3.765600

ILLUSTRATION