第1关:练习-Java包装类之Double类
任务描述
本关任务:将 Double 类转换成其他数据类型。
编程要求
仔细阅读右侧编辑区内给出的代码框架及注释,按照提示编写程序代码。
测试说明
平台将使用测试集运行你编写的程序代码,若全部的运行结果正确,则通关。 可在右侧“测试结果”区查看具体的测试集详情。
开始你的任务吧,祝你成功!
源代码:
/*
* 将 Double 类转换成其他数据类型。
*/
public class Demo {
public static void main(String[] args) {
// 请在下面的Begin-End之间按照注释中给出的提示编写正确的代码
/********** Begin **********/
// 定义int类型变量,值为67,命名为score
int score = 67;
// 创建Double包装类对象,表示变量score的值,命名为score1
Double score1 = new Double(score);
// 将Double包装类转换为double类型,命名为score2
double score2 = score1.doubleValue();
// 将Double包装类转换为float类型,命名为score3
float score3 = score1.floatValue();
// 将Double包装类转换为int类型,命名为score4
int score4 = score1.intValue();
/********** End **********/
System.out.println("Double包装类:" + score1);
System.out.println("double类型:" + score2);
System.out.println("float类型:" + score3);
System.out.println("int类型:" + score4);
}
}