Energy

Energy


Problem Description


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


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


Solution;


import java.util.Scanner;

import java.io.*;

public class TestClass {

public static void main(String[] args) { 

Scanner sc= new Scanner(System.in); 

      Double M= sc.nextDouble();

       Double IT= sc.nextDouble();

       Double FT= sc.nextDouble();

       Double Q=M*(FT-IT)*4184;  

System.out.println("The energy needed is="+Q);  

     }

Post a comment

0 Comments