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 * (finalTemperature –
initialTemperature) * 4184
Description:
where
M is the weight of water in kilograms, temperatures are in degrees
Celsius,
and
energy Q is measured in joules
Solution
import java.util.*;
public class Message {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
float M,initialTemp,finalTemp;
System.out.println("Enter
the amount of water in kilogram");
M=in.nextFloat();
System.out.println("Enter
the initial temperature");
initialTemp=in.nextFloat();
System.out.println("Enter
the final temperature");
finalTemp=in.nextFloat();
System.out.println("The
energy needed is"+(M*(finalTemp-initialTemp)*4184));
}
}
Output:
No comments:
Post a Comment