1. 题目
- 有容乃大
- 难度:简单
2. 题目描述
确定不同整型数据类型在内存中占多大(字节),输出不同整型数据类型在内存中占多大(字节)。
输入描述:
无
输出描述:
不同整型数据类型在内存中占多大(字节),具体格式详见输出样例,输出样例中的?为不同整型数据类型在内存中占的字节数。输出样例如下:
The size of short is ? bytes.The size of int is ? bytes.The size of long is ? bytes.The size of long long is ? bytes.
3. 题解
3.1 分析
Java 中,要查看不同整形类型在内存中所占内存的大小,需要借助其对应的封装类,封装类的 BYTES 属性对应着该类型占用的内存大小;
3.2 代码
/*** Created with IntelliJ IDEA.* Version : 1.0* Author : K* 公众号 : 村雨遥* Website : https://cunyu1943.site* Email : 747731461@qq.com* Date : 2020/12/30 上午9:18* Project : algo-practice* Package : PACKAGE_NAME* Class : BC3* Desc : 有容乃大*/public class BC3 {public static void main(String[] args) {System.out.println("The size of short is " + Short.BYTES + " bytes.");System.out.println("The size of int is " + Integer.BYTES + " bytes.");System.out.println("The size of long is " + Long.BYTES + " bytes.");System.out.println("The size of long long is " + Long.BYTES + " bytes.");}}
