请问这么写符合要求吗

来源:2-13 编程练习

Superdogso

2021-08-06 10:48:17

class HelloWorld {
public static void main(String[] args) {
// 定义int类型变量,值为100
int score = 100;
// 创建Integer包装类对象,表示变量score1的值
Integer score1 = new Integer(score);
// 将Integer包装类转换为double类型
double score3 = score1.doubleValue();
// 将Integer包装类转换为long类型
long score4 = score1.longValue();
// 将Integer包装类转换为int类型
int score5 = score;
//打印输出
System.out.println(score1);
System.out.println(score3);
System.out.println(score4);
System.out.println(score5);
}
}


写回答

1回答

好帮手慕小脸

2021-08-06

同学你好,上述代码有一点小问题:将Integer包装类转换为int类型应该是

int score5 = score.intValue();

而同学写的是int类型重新赋值给另一个int类型

int score5 = score;

祝学习愉快~

1

0 学习 · 9886 问题

查看课程