Java包装类 作业2-1

来源:2-13 编程练习

rudtjd

2023-02-01 13:06:28

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


写回答

1回答

好帮手慕小尤

2023-02-01

同学你好,测试同学代码已完成练习,棒棒哒!继续加油!

祝学习愉快!

0

0 学习 · 9886 问题

查看课程