Contenido del Curso
Introduction to Dart
Introduction to Dart
Basic Math Operations
Numbers
You already know how to use the print()
function. We used to output text, but what about numbers and mathematical calculations?
Remember to use print()
if you want to display your data. Also, there is no need to use quotes (" "
or ' '
) since we are evaluating a mathematical expression this time.
main
void main() { print('Two'); // string print('2'); // string print(2); // number }
Math Operations
Almost no program can do without mathematical calculations, so Dart supports the following mathematical operations:
+
– addition;-
– subtraction;/
– division;*
– multiplication;%
- get the remainder of an integer division (modulo).
main
void main() { print(1+2); // adding numbers print(9-3); // subtracting numbers print(4/2); // division of numbers print(4*2); // multiplication of numbers print(5%2); // Get the remainder from the whole division of 5 by 2 }
Math Expressions
We also can write math expressions.
The sequence of actions will work the same as in mathematics, where 2+2*2 = 6
, because the multiplication is done before the addition.
main
void main() { print(2+2*2); // Output 6 }
¡Gracias por tus comentarios!