Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Basic Math Operations | First Acquaintance with Dart
Quizzes & Challenges
Quizzes
Challenges
/
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

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 5

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

Suggested prompts:

What are some examples of using these operators in Dart?

Can you explain how operator precedence works in Dart?

How do I use the print() function to display the result of a calculation?

Awesome!

Completion rate improved to 4.55

bookBasic Math Operations

Scorri per mostrare il menu

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

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 5
some-alt