Operator | Description | Example | Result |
---|---|---|---|
+ | Addition 加 | x=2 y=2 x+y | 4 |
- | Subtraction 减 | x=5 y=2 x-y | 3 |
* | Multiplication 乘 | x=5 y=4 x*y | 20 |
/ | Division 除 | 15/5 5/2 | 3 2.5 |
% | Modulus (division remainder) 余数 | 5%2 10%8 10%2 | 1 2 0 |
++ | Increment 递增 | x=5 x++ | x=6 |
-- | Decrement 递减 | x=5 x-- | x=4 |
Operator | Example | Is The Same As |
---|---|---|
= | x=y | x=y |
+= | x+=y | x=x+y |
-= | x-=y | x=x-y |
*= | x*=y | x=x*y |
/= | x/=y | x=x/y |
%= | x%=y | x=x%y |
Operator | Description | Example |
---|---|---|
== | is equal to 等于 | 5==8 returns false |
=== | is equal to (checks for both value and type) 等于(检查值和类型)*全吻合才算相等 | x=5 y="5" x==y returns true |
!= | is not equal 不等于 | 5!=8 returns true |
> | is greater than 大于 | 5>8 returns false |
< | is less than 小于 | 5<8 returns true |
>= | is greater than or equal to 大于等于 | 5>=8 returns false |