Value assignment operator
The value assignment operator is a combination from right to left, and the value of the table formula is the value on the right, for example:
Int A = 0; A = 3;
AboveCodeIn, the value of a is 3, and the value of expression A = 3 is also 3. Similar questions are often found in Java questions:
Int A = 0; int B = 5 + (A = 2 );
If we know that the expression A = 2 has a value equal to 2, the problem is very simple.
The four arithmetic operations +-*/% do not need to be explained. Note that only integer division is performed on integers. To get a decimal point value, convert the divisor or divisor to double.
However, the real problem lies not in the four arithmetic operations, but in Java, the floating point and single precision are not accurate because of the limited number of digits. Otherwise, there will be some bugs that are hard to detect.
For example:
Float a = 0.1f; float B = 0.2f; system. Out. println ("A + B =" + (a + B ));
The code above will print 0.3, no problem. However, if I increase the accuracy:
Double A = 0.1; Double B = 0.2; system. Out. println ("A + B =" + (a + B) + "! ");
At this time, the output will be "0.30000000000000004. This error is hard to find. Even Google's Android calculator has such a bug. Therefore, for decimal places, you must note that the expression of numbers is accurate. Do not directly compare them with floating point numbers, but use the absolute value of difference:
Double A = 0.3; Double B = 0.0; ...... if (math. Abs (B-a) <delta ){....}
In Java, all int and so on are signed numbers, so the highest bit represents the symbol, so you must pay attention to the overflow problem.