In this tutorial you will learn about the Dart Arithmetic operators and its application with practical example.
Dart Arithmetic Operators
Arithmetic Operators are used to perform arithmetic operations like addition, subtraction, multiplication, division, %modulus, exponent, etc. Let variable a holds 20 and variable b holds 10, then −
Operator | Name | Description | Example |
---|---|---|---|
+ |
Addition |
Addition of given operands |
a+b returns 30 |
- |
Subtraction |
Subtraction of second operand from first |
a-b returns 10 |
-expr |
Unary Minus |
reverse the sign of the expression |
-(a-b) returns -10 |
* |
Multiply |
Multiplication of given operands |
a*b returns 200 |
/ |
Division |
Returns Quotient after division |
a/b returns 2 |
~/ |
Division(Int) |
Return an integer result |
a/b returns 2 |
% |
Modulus |
Returns Remainder after division |
a%b returns 0 |
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 |
void main() { var a = 20; var b = 10; print("W3Adda - Dart Arithmetic Operators"); print("a+b = ${a+b}"); print("a-b = ${a-b}"); print("a/b = ${a/b}"); print("a*b = ${a*b}"); print("a%b = ${a%b}"); print("a~/b = ${a~/b}"); } |
When you run the above Dart program, you will see following output.
Output:-