Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Basic Math Operations | First Acquaintance with Dart
Introduction to Dart

bookBasic Math Operations

You already know how to use the print() function to display text. It can also be used to output numbers and perform mathematical calculations. Use print() whenever you want to display data. Do not use quotes (" " or ' '), since this time you’re evaluating a mathematical expression.

main.dart

main.dart

copy
12345
void main() { print('Two'); // String print('2'); // String print(2); // Number }
Note
Study More

In Dart, if a number is written in quotes ("123"), it is treated as text (a string) rather than an actual number. This means you can't perform math operations like addition or multiplication on it.

Almost no program can do without mathematical calculations, so Dart supports the following mathematical operations:

main.dart

main.dart

copy
1234567
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 }

You can also write mathematical expressions. The order of operations follows standard math rules, so 2 + 2 * 2 = 6 because multiplication is performed before addition.

main.dart

main.dart

copy
123
void main() { print(2+2*2); }
Note
Note

The same rule applies to brackets, expressions inside parentheses are calculated first, just like in regular mathematics.

question mark

Select the correct numbers multiplication.

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 5

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Awesome!

Completion rate improved to 4.55

bookBasic Math Operations

Desliza para mostrar el menú

You already know how to use the print() function to display text. It can also be used to output numbers and perform mathematical calculations. Use print() whenever you want to display data. Do not use quotes (" " or ' '), since this time you’re evaluating a mathematical expression.

main.dart

main.dart

copy
12345
void main() { print('Two'); // String print('2'); // String print(2); // Number }
Note
Study More

In Dart, if a number is written in quotes ("123"), it is treated as text (a string) rather than an actual number. This means you can't perform math operations like addition or multiplication on it.

Almost no program can do without mathematical calculations, so Dart supports the following mathematical operations:

main.dart

main.dart

copy
1234567
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 }

You can also write mathematical expressions. The order of operations follows standard math rules, so 2 + 2 * 2 = 6 because multiplication is performed before addition.

main.dart

main.dart

copy
123
void main() { print(2+2*2); }
Note
Note

The same rule applies to brackets, expressions inside parentheses are calculated first, just like in regular mathematics.

question mark

Select the correct numbers multiplication.

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 5
some-alt