数据类型:
1.基本数据类型
1.1 整型
1)、byte short int long
2)、默认类型int 默认值0
3)、学生对象的年龄、计数器等
1.2 浮点型
1)、float double
2)、默认类型double 默认值0.0
3)、员工对象的工资、奖金,商品的价格等
1.3 字符型
1)、char
2)、学生对象
3)、String 定义字符串
1.4 布尔类型
1)、boolean
2)、true、false 默认值false
3)、学生对象的性别、标志位等
2.引用数据类型
2.1 String、System等API中的类
2.2 Demo1、Demo2、Test等自定义的类
2.3 String[]数组等
数据类型使用场景:
1.申明变量时,数据类型 变量名 = 值;
2.方法的形式参数
3.方法的返回值
*/
public class Demo2{
public static void main(String[] args){
//变量(Variable) 数据类型 变量名 = 值;
//整型 默认类型int 默认值0
byte b1 = 100;
//byte b2 = 128; //-128~127
System.out.println(“b1 = “+b1);
//System.out.println(“b2 = “+b2);
short s = 2000;
System.out.println(“s = “+s);
int i = 15;
System.out.println(“i = “+i);
long l = 125454555L;
System.out.println(“l = “+l);
//浮点型 默认类型double 默认值0.0
float f = 23.5F;
System.out.println(“f = “+f);
double d = 22.2;
System.out.println(“d = “+d);
//字符型
char c1 = ‘a’;
System.out.println(“c1 = “+c1);
char c2 = ‘中’;
System.out.println(“c2 = “+c2);
//char c3 = ‘幺蛾子’;
//System.out.println(“c3 = “+c3);
//布尔类型
boolean o1 = true;
System.out.println(“o1 = “+o1);
boolean o2 = false;
System.out.println(“o2 = “+o2);
//变量未赋值,不能直接使用
//变量只在它所属的范围内有效
//一行上可以定义多个变量,但是不建议
int t=10 , m=20; //不建议
System.out.println(“t = “+(t+10));
System.out.println(“m = “+(m+10));