Once you know the eight basic data types, it is necessary to understand the precedence of operators in use. Specific example:
It is important to note that the precedence of the coercion type conversion is in front of the multiplication and is behind the monocular operator, which is a relatively error-prone place. For example, use Math.random () to get an integer of 5 10 or less. Use the following code:
1 int [] a=newint[5]; 2 for (int i=0;i<5;i++) 3 {4 a[i]= (int) math.random () *10; 5 }6 System.out.println (Arrays.tostring (a));
At this point the console will output 5 0, because the coercion type conversion priority is higher than the multiplication, first rounding down and then the multiplication operation.
It is also important to note the "prefix" and "suffix" forms of the self-increment decrement operator, where the result is different when assigned or output, such as:
int a=0; int b=0; System.out.println (a+ +); System.out.println (++b);
The output is 0, 1; This indicates that the "suffix" form is assigned first and then the self-increment operation, whereas the "prefix" form is the first self-increment operation and then the value is assigned.
Common operators in Java and their order of precedence