变量:
数据类型:
基本类型:short/byte(1byte)/char(2byte)-->int(4byte)-->long(8byte)-->float(8byte)-->double(16byte,默认)、boolean
java变量
从本质上讲,变量其实是内存里面的一小块区域,.exe文件必须被放在内存才可以被加载执行
类型转换:
例子:
byte a=2;
a=a+2;
System.out.print("a="+a);//报错
解决方式:强制转换
a=byte(a+2);
整数类型:
声明long型常量需要加‘l’或者'L'
如:long l1=8888L;//必须加L否则会出错
浮点常量
float f=123.5f;//不加f会出错
double d=123.6;//默认,正确
例子2:
损失精度的情况:
float f=12.5f;
long l1=(float)f;//输出12
运算符
算式运算符