JAVA 8种基本数据类型大小

在Java中,基础数据类型的大小在所有机器上都是一样的

public class DataTypeByte { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(“byte所占位数” + Byte.SIZE); System.out.println(“byte所占字节数” + Byte.SIZE/8); System.out.println(“int所占位数” + Integer.SIZE); System.out.println(“int所占字节数” + Integer.SIZE/8); System.out.println(“short所占位数” + Short.SIZE); System.out.println(“short所占字节数” + Short.SIZE/8); System.out.println(“float所占位数” + Float.SIZE); System.out.println(“float所占字节数” + Float.SIZE/8); System.out.println(“double所占位数” + Double.SIZE); System.out.println(“double所占字节数” + Double.SIZE/8); System.out.println(“char所占位数” + Character.SIZE); System.out.println(“char所占字节数” + Character.SIZE/8); System.out.println(“long所占位数” + Long.SIZE); System.out.println(“long所占字节数” + Long.SIZE/8); }

}

运行结果如图所示

经验分享 程序员 微信小程序 职场和发展