On Java variable assignment operator and related examples [original]
In Java programs, a large number of calculations need to be performed, so the operation symbols should be used. Let's explain how to use the Java assignment operator.
The assignment operator is represented by the symbol "=". It is a binary operator (processing two operands). Its function is to assign the value contained in the right operand to the left operand. For example:
This expression assigns 100 to variable a. The operand on the left must be a variable, while the one on the right can be any expression, including variables (such as a, number), constants (123, 'book') and valid expressions (such as 55 * 66).
1: Use the assignment operator to assign a value to the variable, and the code is as follows:
Following the algorithm of assignment operator, it can be seen that the system will first calculate the value of a + B and assign its operation result to variable C.
Since the assignment operator "=" will first obtain the processed result of the expression on the right, if an expression contains more than two "=" operators, it will be processed from the rightmost "=".
2: Create a class test001 in the project, define variables in the main method, and assign values to variables using assignment operators.
The operation result is:
C value: 19 b value: 19
Note: assignment operators can be used together in Java, such as:
x=y=z=9;
In this statement, the variables X, y, Z all get the same value 9 However, this assignment statement is not recommended in program development.
summary
The above is the whole content of this article. I hope this article can help you learn Java.