The basic form of variable definition in Java is "data type variable name = initialization value;"; the basic data types include byte, short, int, long, float, double, char, and boolean. Multiple variables of the same type can be defined at the same time, and a comma-separated list is required, for example "int a=1,b=2;".
#Variables provide named storage that programs can operate on. Every variable in Java has a type, which determines the size and layout of the variable's memory; the range of values that can be stored in that memory; and the set of operations that can be applied to the variable.
Variables need to be declared and defined before they can be used. The following is the basic form of variable declaration and definition-
数据类型 变量名 = 初始化值;
Basic data types:
byte, short, int, long, float, double, char, boolean
Note:
The default integer is int type. When defining long type data, add L after the data.
Floating point numbers default to double type. When defining float type data, add F after the data.
To declare multiple variables of the same type, you can use a comma-separated list.
The following is an example of variable declaration and initialization in Java -
int a, b, c; // 声明三个int类型变量:a, b 和 c int a = 10, b = 10; // 初始化它们的值 byte B = 22; // 声明并初始化一个 byte 类型的变量:B double pi = 3.14159; // 声明并赋值一个 double 类型的变量:PI char a = 'a'; // 声明char类型变量 a,并初始化值为:'a'
The above is the detailed content of How to define variables in java?. For more information, please follow other related articles on the PHP Chinese website!