变量定义
public class Main { public static void main(String[] args) { // 定义byte类型的变量
byte b = 10;
System.out.println(b); // 定义short类型的变量
short s = 100;
System.out.println(s); // 定义int类型的变量
int i = 1000;
System.out.println(i); // 定义long类型的变量
long l = 100000000L; // 此处需要在值的末尾加L
System.out.println(l); // 定义float类型的变量
float f = 12.34F; // 此处需要再值的末尾加F
System.out.println(f); // 定义double类型的变量
double d = 12.34;
System.out.println(d); // 定义char类型的变量
char c = 'a';
System.out.println(c); // 定义boolean类型的变量
boolean bb = true;
System.out.println(bb); }
}
定义变量的注意事项:
A:变量未赋值,不能使用
B:变量只在所属范围内有效,变量属于它所在的那对大括号
C:一行可以定义多个变量(不建议)