java中的8种基本数据类型占的位数以及取值范围

来源:互联网 发布:常用cmd 网络命令 编辑:程序博客网 时间:2024/05/16 10:22
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;/** * java基本数据类型的字节、取值范围 * 由于java.lang.Boolean没用提供size方法, * 所以这里只具体列出了8种基本数据类型中的7种 * @author Howard * 2017年2月24日 */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);}}



0 0
原创粉丝点击