I. Variables
1: variable definition: The expression of a bucket.
2: common Java Data Types
INT: integer. Used to store integers.
Double: Double Floating Point type. Stores decimal numbers.
CHAR: character type. Stores a single character.
String: string type. Stores a string of characters.
3: two ways to define variables:
01. Declare and assign values first
Example:
Int money; // declare a variable
Money = 100; // assign a value to the variable
02. simultaneous assignment of declarations
Example:
Int money = 100;
4: variable naming rules
01. It must start with a letter, underscore "_", or "$;
02. A number may exist, but cannot begin with a number;
03. No other symbols except the underscore "_" or "$;
04: you cannot use Java keywords for variable names, such as int, class, and public.
Generally, the first letter of a variable name is lowercase, And the last letter of a variable name is uppercase. (Camel naming method)
Ii. operators:
Expression definition: A combination of symbols and operands.
1: Value assignment operator: "=". Assign the result of the expression on the right of the equal sign to the variable on the left of the equal sign.
2: arithmetic operators:
+: Addition Operator
-: Subtraction Operator
*: Multiplication Operator
/: Division integer Operator
%: Division remainder Operator
3: ++ itself plus one;
-- Minus one;
++ Or -- before a variable: this means that the variable itself is first added and then involved in the operation.
+ + Or -- after the variable: it means that the variable is involved in the calculation first, and then added to itself.
Num + = 1: num = num + 1
Num + = 2: num = num + 2
4: Relational operators
>: Greater
<: Less
>=: Greater than or equal
<=: Less than or equal
=: Equal
! =: Not equal
5: logical operators
&: Corresponds
|: Or
! : Non (reverse)
Iii. Data type conversion:
Rule 1: If an operand is of the double type, the entire expression can be upgraded to the double type.
Example:
Int score = 80;
Double newscore = score;
The newscore output value is 80.0.
Rule 2: meets the conditions for automatic type conversion
01: the two types must be compatible;
02: The target type is greater than the source type.
Data type conversion can be divided:
(1) automatic data type conversion (amplification and conversion)
(2) Forced data type conversion: convert a type with a large width to a type with a small width (narrow conversion)
Example:
Double A = 84.5;
Int B = (INT) B/2;