基本数据类型
1.byte
占1个字节,-128~127 (-27 ~ 27-1)
2.short
占2个字节,-32768~32767 (-215 ~ 215-1)
3.int
占4个字节,-2147483648 ~ 2147483647 (-231~231-1)
4.long
占8个字节,-9223372036854775808~9223372036854775807 (-263 ~ 263-1)
5.float
占4个字节
6.double
占8个字节
7.char
占2个字节
8.boolean
占1位,其值只有true和false两个
进制表示
public class t1 {
public static void main(String[] args)
{
int a=10;//10进制
int b=010;//8进制
int c=0x10;//16进制
System.out.println(a);//a=10
System.out.println(b);//b=8
System.out.println(c);//c=16
}
}
类型转换
1.自动转换
只能由小转到大,不能从大转到小
低----->高
byte,short,char,int,long,float,double
int a=10;
byte b=a;//错误
long c=a;//正确
2.强制转换
int a=10;
byte b=byte(a);
注意:
- 不能对boolean类型转换
- 转换时注意内存溢出和精度问题