Java基本数据类型大小

不同整型数据类型在内存中占多大(字节),具体格式详见输出样例,输出样例中的?为不同整型数据类型在内存中占的字节数。输出样例如下:
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.

public class Main{
    public static void main(String args[]){
        System.out.println("The size of short is " + Short.SIZE / 8 + " bytes.");
        System.out.println("The size of int is " + Integer.SIZE / 8 + " bytes.");
        System.out.println("The size of long is " + Long.SIZE / 8 +" bytes.");
        System.out.println("The size of long long is " + Long.SIZE / 8 + " bytes.");
    }
}

运行输出如下:
在这里插入图片描述


版权声明:本文为yang_1104原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。