and final temperatures of the water. The formula to compute the energy is
Q = M * (finalTemperature – initialTemperature) * 4184
where M is the weight of water in kilograms, temperatures are in degrees Celsius, and energy Q is measured in joules.
Solution:
Scanner s = new Scanner(System.in);
double amountOfWater, initialTemperature, finalTemperature, energy;
System.out.print("Enter the amount of water in kilograms:");
amountOfWater = s.nextDouble();
System.out.print("Enter the initial temperature:");
initialTemperature = s.nextDouble();
System.out.print("Enter the final temperature:");
finalTemperature = s.nextDouble();
energy = amountOfWater * (finalTemperature - initialTemperature) * 4184;
System.out.print("The energy needed is " + energy);
}
No comments:
Post a Comment