首页 > 试题广场 >

(科学:计算能量)编写程序,计算将水从初始温度加热到最终温

[问答题]
 (科学:计算能量)编写程序,计算将水从初始温度加热到最终温度所需的能量。程序应该提示 用户输人水的重量(以千克为单位),以及水的初始温度和最终温度。计算能量的公式是:
 Q - M X (最终*度 - 初始潘度)X 4184
这里的 M是以千克为单位的水的重量,温度以摄氏度为单位,而能置 Q以焦耳为单位。下 面是一个运行示例: 

package AA;
import java.util.Scanner;
public class ah {
    public static void main(String[] args){
                double kilograms=0,temperature1=0,temperature2;
                System.out.print("Enter the amount of water in kilograms:");
                Scanner in=new Scanner(System.in);
                kilograms=in.nextDouble();
                System.out.print("Enter the initial temperature:");
                Scanner s=new Scanner(System.in);
                temperature1=s.nextDouble();
                System.out.print("Enter the final temperature:");
                Scanner m=new Scanner(System.in);
                temperature2=m.nextDouble();
                double Q;
                Q = kilograms*(temperature2-temperature1)* 4184;
                System.out.print("The energy needed is "+String.format("%.1f",Q));
                
                
    }

}
发表于 2021-04-06 10:25:07 回复(0)