资讯动态

头歌实践教学平台:Java面向对象-包装类(二)

发布时间:2026/9/12 21:10:11 来源:尧图企业网站定制
第2关包装类转换成其他数据类型任务描述本关任务将包装类转换成其他数据类型。相关知识为了完成本关任务你需要掌握1.如何将包装类转换成其他基本数据类型。将包装类转换成其他数据类型很简单我们来看一个例子就知道了Integer i new Integer(100);//转换成double类型double d i.doubleValue();System.out.println(d的值 d);//转换成float类型float f i.floatValue();System.out.println(f的值 f);相信你已经明白怎么进行转换了。Integer i new Integer(100);//转换成double类型double d i.doubleValue();System.out.println(d的值 d);//转换成float类型float f i.floatValue();System.out.println(f的值 f);相信你已经明白怎么进行转换了。编程要求请仔细阅读右侧代码根据方法内的提示在Begin - End区域内进行代码补充具体任务如下将int类型数据转换成其他数据类型。将int类型数据转换成其他数据类型。测试说明补充完代码后点击测评平台会对你编写的代码进行测试当你的结果与预期输出一致时即为通过。预期输出Integer包装类67double类型67.0float类型67.0int类型67开始你的任务吧祝你成功package step2;public class Task {public static void main(String[] args) {//请在此添加实现代码/********** Begin **********/// 定义int类型变量值为67int score 67;// 创建Integer包装类对象表示变量score的值Integer score1 new Integer(score);// 将Integer包装类转换为double类型double score2 score1.doubleValue();// 将Integer包装类转换为float类型float score3 score1.floatValue();// 将Integer包装类转换为int类型int score4 score1.intValue();System.out.println(Integer包装类 score1);System.out.println(double类型 score2);System.out.println(float类型 score3);System.out.println(int类型 score4);/********** End **********/}}有任何问题都可以随时关注私信

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价