Dart int isEven
Syntax & Examples

int.isEven property

The `isEven` property in Dart returns true if and only if this integer is even.


Syntax of int.isEven

The syntax of int.isEven property is:

 bool isEven 

This isEven property of int returns true if and only if this integer is even.

Return Type

int.isEven returns value of type bool.



✐ Examples

1 Check if a positive integer is even

In this example,

  1. We create an integer variable number1 with the value 10.
  2. We access its isEven property to check if it is even.
  3. We then print the result to standard output.

Dart Program

void main() {
  int number1 = 10;
  bool isEven1 = number1.isEven;
  print('$number1 is even: $isEven1');
}

Output

10 is even: true

2 Check if a positive integer is odd

In this example,

  1. We create an integer variable number2 with the value 7.
  2. We access its isEven property to check if it is even.
  3. We then print the result to standard output.

Dart Program

void main() {
  int number2 = 7;
  bool isEven2 = number2.isEven;
  print('$number2 is even: $isEven2');
}

Output

7 is even: false

3 Check if a negative integer is even

In this example,

  1. We create an integer variable negativeNumber with the value -6.
  2. We access its isEven property to check if it is even.
  3. We then print the result to standard output.

Dart Program

void main() {
  int negativeNumber = -6;
  bool isEvenNegative = negativeNumber.isEven;
  print('$negativeNumber is even: $isEvenNegative');
}

Output

-6 is even: true

Summary

In this Dart tutorial, we learned about isEven property of int: the syntax and few working examples with output and detailed explanation for each example.