1.java中的数据类型及所占字节:
整形 byte;int short;long(1 4 2 8) 浮点型 float;double;(4 8) 布尔型 boolean(1) 字符型 char(2)
数据类型的特点
- 随便输入一个整数,默认类型是int
- long 类型则需要在后面加入L/l
-
long a=424444L; - .随便输入一个小数,
float需要在数后面加入F/; 6. float b=3.14f; 7.
3
.boolean 类型记录是真假4 8. boolean c=true; 9. boolean c2= false; 10.4
.引用拓展一种数据类型 11. String 字符串类型; 12. String name ="张三“; 13. 3.自动类型的转换
byte-short-int -long-float-double; char
b.表达式的类型转化
-
最后转化成优先级最高的类型
-
在表达式中,byte short char 是自动转化成int 类型
-
short a=10;
-
byte b=20;
-
int sum=a+b;//此处用int类型,因为short byte 已经自动转化;
-
得到小数的技巧
-
int i=5;
-
int j=2;
-
m=(1.0*i/j)//得到了2.5
标识符:
- 标识符以字母,数字下划线,美元单位¥组成;
- 强制要求:不能以数字做开头,且不能与关键字重复;
- 中国也是标识符(中文字符);
- 尽量使用英文标识符,且开头小写,满足驼峰模式如 int studyNumber=10;
ASCII码值运用
System.out.println('a'+10);//97+10
System.out.println('A'+10);//65+10