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

Course Content

Introduction to Dart

Introduction to Dart

1. First Acquaintance with Dart
2. Variables and Data Types
3. Conditional Statements
4. List and String
5. Loops

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.

dart

main

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:

  • + – addition;
  • - – subtraction;
  • / – division;
  • * – multiplication;
  • % - get the remainder of an integer division (modulo).
dart

main

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.

dart

main

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

Select the correct numbers multiplication.

Select the correct answer

Everything was clear?

Section 1. Chapter 5
We're sorry to hear that something went wrong. What happened?
some-alt