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

bookBasic 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

main.dart

copy
12345
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:

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 }

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

main.dart

copy
123
void main() { print(2+2*2); // Output 6 }
question mark

Select the correct numbers multiplication.

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 5

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Awesome!

Completion rate improved to 4.55

bookBasic Math Operations

Swipe to show menu

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

main.dart

copy
12345
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:

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 }

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

main.dart

copy
123
void main() { print(2+2*2); // Output 6 }
question mark

Select the correct numbers multiplication.

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 5
some-alt