DART的运算符
尽管 C 和 C++ 开发人员应该熟悉大多数 DART 运算符,但在这里我们将讨论算术运算符。
- 算术运算符
Dart支持不同的算术运算符。
| 运算符 | 说明 |
|---|---|
| + | 加法 |
| - | 减法 |
| * | 乘法 |
| / | 除法 |
| -expr | 取负值 |
| ~/ | 除法 |
| % | 取余 |
| ++var | 值等于var+1 (先自增再赋值) |
| var++ | 值等于var (先赋值再自增) |
| --var | 值等于var-1(先自减再赋值) |
| var-- | 值等于var (先赋值再自减) |
算术运算符的示例
void main() {
int a=4,b=3;
print("Welcome in DART Operator");
print("The addition of $a and $b is ${a+b}");
print("The subtraction of $a and $b is ${a/b}");
print("The multiplication of $a and $b is ${a*b}");
print("The division of $a and $b is ${a/b}");
print("The negation of $a and $b is ${a~/b}");
print("The reminder of $a and $b is ${a%b}");
print("The pri-increment of $a is ${++a}");
print("The post-increment of $a is ${a++}");//here a value is 5 because value of a is also increse by one in pri-increment //operation.
print("The pri-decrement of $b is ${--b}");
print("The post-decrement of $b is ${b--}");//here b value is 2 because value of b is also decrese by one in pri-decrement //operation.
}
日期:2020-04-11 23:04:01 来源:oir作者:oir
