Java 2.10(科学:计算能量)编写程序,计算将水从初始温度加热到最终温度所需的能量。程序应该提示用户输入水的重量(以千克为单位),以及水的初始温度和最终温度。

计算能量的公式是:Q = M x (初始温度 - 最终温度) x 4184

这里的M以千克为单位的水的动量,温度以摄氏度为单位,而能量Q是以焦耳为单位。

下面是一个运算示例:

Enter the amount of water in kilograms: 55.5

Enter the initial temperature: 3.5

Enter the final temperature:10.5

The energy needed is 1625484.0 

package Second;

import java.util.Scanner;

public class T {

	public static void main(String[] args) {
		System.out.println("Enter the amount of water in kilograms: ");
	    Scanner input = new Scanner(System.in);
	    double M = input.nextDouble();//水的重量
	    System.out.println("Enter the initial temperature: ");
	    double IT = input.nextDouble();//初始温度
	    System.out.println("Enter the final temperature: ");
	    double FT = input.nextDouble();//最终温度
	    double Q = 0;
	    Q = M * (FT - IT) * 4148;
	    System.out.println("The energy needed is :" + Q);
	}

}

 输出

Enter the amount of water in kilograms: 
55.5
Enter the initial temperature: 
3.5
Enter the final temperature: 
10.5
The energy needed is :1611498.0

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
ASP函数 IsNull()   FUNCTION: 判断一对象是否为空,返回布尔值.   SYNTAX: IsNull(expression)   ARGUMENTS:   EXAMPLE: $#@60;%       Dim i       response.write IsNull(i)       %>   RESULT: False IsNumeric()   FUNCTION: 判断一对象是否为数字,返回布尔值.   SYNTAX: IsNumeric(expression)   ARGUMENTS:   EXAMPLE: $#@60;%        i = "345"        response.write IsNumeric(i)       %>   RESULT: True 就算数字加了引号,ASP还是认为它是数字。 IsObject()   FUNCTION: 判断一对象是否为对象,返回布尔值.   SYNTAX: IsObject(expression)   ARGUMENTS:   EXAMPLE: $#@60;%        Set con = Server.CreateObject("ADODB.Connection")        response.write IsObject(con)       %>   RESULT: True LBound()   FUNCTION: 返回指定数组维的最小可用下标.   SYNTAX: Lbound(arrayname [, dimension])   ARGUMENTS: ; dimension 指明要返回哪一维下界的整数。使用 1 表示第一维,2 表示第二维,以此类推。如果省略          dimension 参数,默认值为 1.   EXAMPLE: $#@60;%        i = Array("Monday","Tuesday","Wednesday")        response.write LBound(i)        %>   RESULT: 0 LCase()   FUNCTION: 返回字符串的小写形式   SYNTAX: Lcase(string)   ARGUMENTS: string is any valid string expression.   EXAMPLE: $#@60;%        strTest = "This is a test!"        response.write LCase(strTest)       %>   RESULT: this is a test! Left() <   FUNCTION: 返回字符串左边第length个字符以前的字符(含第length个字符).   SYNTAX: Left(string, length)   ARGUMENTS:   EXAMPLE: $#@60;%       strTest = "This is a test!"       response.write Left(strTest, 3)       %>   RESULT: Thi Len()   FUNCTION: 返回字符串的长度.   SYNTAX: Len(string | varName)   ARGUMENTS:   EXAMPLE: $#@60;%        strTest = "This is a test!"        response.write Len(strTest)       %>   RESULT: 15 LTrim()   FUNCTION: 去掉字符串左边的空格.   SYNTAX: LTrim(string)   ARGUMENTS:   EXAMPLE: $#@60;%       strTest = " This is a test!"       response.write LTrim(strTest)       %>   RESULT: This is a test! Mid()   FUNCTION: 返回特定长度的字符串(从start开始,长度为length).   SYNTAX: Mid(string, start [, length])   ARGUMENTS:   EXAMPLE: $#@60;%        strTest = "This is a test! Today is Monday."        response.write Mid(strTest, 17, 5)       %>   RESULT: Today
1. 将模型保存为.pb文件 在tensorflow2.10中,可以使用以下代码将模型保存为.pb文件: ```python import tensorflow as tf # 构建模型 model = tf.keras.Sequential([ tf.keras.layers.Input(shape=(28, 28, 1)), tf.keras.layers.Conv2D(32, 3, activation='relu'), tf.keras.layers.Flatten(), tf.keras.layers.Dense(10, activation='softmax') ]) # 训练模型 # 保存模型为.pb文件 tf.saved_model.save(model, '/path/to/model.pb') ``` 2. 编写混淆矩阵的python程序 混淆矩阵是评估分类模型性能的一种常用方法。下面是一个基于tensorflow2.10编写的计算混淆矩阵的Python程序: ```python import tensorflow as tf import numpy as np from sklearn.metrics import confusion_matrix # 加载测试数据集 (x_test, y_test), _ = tf.keras.datasets.mnist.load_data() x_test = x_test.astype('float32') / 255. x_test = np.expand_dims(x_test, axis=-1) y_test = tf.keras.utils.to_categorical(y_test, 10) # 加载模型 model = tf.saved_model.load('/path/to/model.pb') # 进行预测 y_pred = model(x_test) # 将预测结果转换为标签 y_pred = np.argmax(y_pred, axis=-1) y_test = np.argmax(y_test, axis=-1) # 计算混淆矩阵 cm = confusion_matrix(y_test, y_pred) print(cm) ``` 在上面的程序中,首先加载测试数据集,然后加载保存在.pb文件中的模型。接着,使用测试数据集进行预测,并将预测结果转换为标签。最后,使用sklearn.metrics中的confusion_matrix函数计算混淆矩阵,并输出结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山山4332

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值