数据类型的分类
基本数据类型:四大类八小种
第一类:整数类型
byte,short,int,long
第二类:浮点数类型
float,double
第三类:字符型
char
第四类:布尔型
boolean
引用数据类型:类(class),接口(interface),数组([])
变量的定义格式:
数据类型 变量名 = 初始值
数据类型:byte, short, int , long, float, double, char, boolean
定义变量的注意事项:
整型默认是int类型,定义long类型变量的时候,后面要加字母L
浮点型默认是double类型,定义float类型变量的时候,后面要加字母F
使用时注意的事项:
变量未赋值,不能使用
变量只有在它所属的范围内有效
一行上可以定义多个变量但不建议这样写
举例
public class VariableDemo01 {
public static void main(String[] args) {
//byte类型的变量
byte b = 5;
System.out.println(b);
//short类型变量
short s = 10;
System.out.println(s);
//int 类型变量
int i = 20;
System.out.println(i);
//long类型变量
long l = 10000000L;
System.out.println(l);
//float类型变量
float f = 10.5F;
System.out.println(f);
//double类型变量
double d = 3.14;
System.out.println(d);
//char类型变量
char c = 'a';
System.out.println(c);
//boolean类型变量
boolean b1 = true;
boolean b2 = false;
System.out.println(b1);
System.out.println(b2);
}
}