Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Properties of Numbers | Variables and Data Types
Introduction to Dart
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

bookProperties of Numbers

We already know about int and double. This сhapter will teach how to work with these data types.

What are Properties?

In programming, just like in our life, things have their properties. It applies to all things. The properties of cars include brand, maximum speed, engine capacity, etc. The book properties include the author, genre, and number of pages.

To find out what is stored in the property, you need:

Properties of int

  • isEven :

This property stores a bool value about whether the number is even or not. If the number is even, true is stored in the property. If it is negative, then false.

dart

main

copy
1234
void main(){ int number = 2; print(number.isEven); // `true` }

We don't need to program to know that 2 is even. But if the result in the variable stores the result of a mathematical expression, the properties will be beneficial to learn more.

dart

main

copy
1234
void main(){ int result = 2 * -3 * -3 + 13 + 31 * -3 * 31; print(result.isEven); // `true` or `false` ? }

The computer calculated the expression (result = -2852). The number is even.

  • isNegative :

We will get true if the number is negative. If the number is positive or 0, we will get false.

dart

main

copy
1234
void main(){ int number = 4; print(number.isNegative); // `false` }

All the properties listed above are properties of the int type. These properties are not present in other data types (even in double, although they are also numbers).

Every data type has its own properties, and you will get acquainted with them eventually. But at this stage, it's crucial to understand that all data types are different, and each one requires its own approach.

question-icon

Use the isEven property and check if an even number is stored in the num variable.

print();

Натисніть або перетягніть елементи та заповніть пропуски

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 3
some-alt