java中有8种基本数据类型:byte、int、short、long、boolean、char、float、double对应的类为:Byte、Int、Short、Long、Boolean、Charecter、Float、Double其中:b
java中有8种基本数据类型:byte、int、short、long、boolean、char、float、double
对应的类为:Byte、Int、Short、Long、Boolean、Charecter、Float、Double
其中:boolean是逻辑型,char是文本型,byte、short、int、long是整数型,float、double是浮点型
byte:1字节 -128~127
short:2字节 -2^15~2^15-1
int :4字节 -2^31~2^31-1
long:8字节 -2^63~2^63-1
boolean:1字节 true false(java中不能以0或非0代替)
float: 4字节 -3.403E38~3.403E38
double:8字节 -1.798E308~- 4.9E324
char:2字节 ’u0000‘~' ’uffff '(16进制的,换算过来即0~65535)
(1字节等于8位)
实例:
package com.Howard.test01;
public class BasicDataTypeTest {
public static void main(String[] args) {
System.out.println(Integer.TYPE+":"+Integer.SIZE
+" "+Integer.MIN_VALUE+"~"+Integer.MAX_VALUE);
System.out.println(Short.TYPE+":"+Short.SIZE
+" "+Short.MIN_VALUE+"~"+Short.MAX_VALUE);
System.out.println(Byte.TYPE+":"+Byte.SIZE
+" "+Byte.MIN_VALUE+"~"+Byte.MAX_VALUE);
System.out.println(Long.TYPE+":"+Long.SIZE
+" "+Long.MIN_VALUE+"~"+Long.MAX_VALUE);
System.out.println(Character.TYPE+":"+Character.SIZE
+" "+(int)Character.MIN_VALUE+"~"+(int)Character.MAX_VALUE);
System.out.println(Float.TYPE+":"+Float.SIZE
+" "+Float.MIN_VALUE+"~"+Float.MAX_VALUE);
System.out.println(Double.TYPE+":"+Double.SIZE
+" "+Double.MIN_VALUE+"~"+Double.MAX_VALUE);
}
}
运行结果:
更多java相关文章推荐:java开发入门
--结束END--
本文标题: java中的数据类型各占多少字节(位)
本文链接: https://www.lsjlt.com/news/3737.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-03
2024-04-03
2024-04-01
2024-01-21
2024-01-21
2024-01-21
2024-01-21
2023-12-23
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0