byte占1个字节,char占2个字节,short占2个字节,int占4个字节,long占8个字节,float占8个字节,double占16个字节。
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package test;
/**
*
* @author huanghuankun
*/
public class IntAndLong {
//int占4个字节,long占8个,float占8个,double占16个。
public static void main(String[] arg) {
int i_max = Integer.MAX_VALUE;
int i_min = Integer.MIN_VALUE;
System.out.println("int:max=" + i_max + ",min=" + i_min);
long l_max = Long.MAX_VALUE;
long l_min = Long.MIN_VALUE;
System.out.println("long:max=" + l_max + ",min=" + l_min);
double d_max = Double.MAX_VALUE;
double d_min = Double.MIN_VALUE;
System.out.println("double:max=" + d_max + ",min=" + d_min);
long lTmp = i_max + 1;
System.out.println("lTmp="+lTmp);
System.out.println("i_max+1="+(i_max+1));//溢出
System.out.println("i_min-1="+(i_min-1));
}
}输出结果:
int:max=2147483647,min=-2147483648
long:max=9223372036854775807,min=-9223372036854775808
double:max=1.7976931348623157E308,min=4.9E-324
lTmp=-2147483648
i_max+1=-2147483648
在进行数据运算过程中需要注意溢出问题。