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.dart
12345void 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:
main.dart
1234567void 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.dart
123void main() { print(2+2*2); // Output 6 }
¡Gracias por tus comentarios!
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Awesome!
Completion rate improved to 4.55
Basic Math Operations
Desliza para mostrar el menú
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.dart
12345void 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:
main.dart
1234567void 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.dart
123void main() { print(2+2*2); // Output 6 }
¡Gracias por tus comentarios!