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

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.

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  5

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  5
some-alt