1. When several variables are involved in the operation, the result type depends on the variable type that represents the largest range in these variables.
For example, there are integer int, double float double, and short integer short in the involved variable.
The final result type is double.
2. int A = 1;
Int B = 2;
Double C = (double) A/B;
The above CodeA and B are both integer, but a is converted to an anonymous variable through the (double) a conversion.
The variable type is double, but note that a itself is still int, not double,
In this way, (double) a/B is the double type divided by the int type, and the result is naturally the double type.
3. modulo operator: %.
Int A = 5;
Int B = 3;
Int c = A % B;
The running result of the above Code is 2, because the result of dividing 5 by 3 is 1 + 2.
Rule of modulus: The result symbol of modulus is always the same as that of divisor.
Int A = 5;
Int B =-3;
Int c = A % B;
If the divisor is 5, the modulo result is 2.
Int A =-5;
Int B = 3;
Int c = A % B;
If the divisor is-5, the modulo result is-2.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.