Dart int isOdd
Syntax & Examples


int.isOdd property

The `isOdd` property in Dart returns true if and only if the integer is odd.


Syntax of int.isOdd

The syntax of int.isOdd property is:

 bool isOdd 

This isOdd property of int returns true if and only if this integer is odd.

Return Type

int.isOdd returns value of type bool.



✐ Examples

1 Check if a positive number is odd

In this example,

  1. We assign the value 5 to the integer variable num1.
  2. We check if num1 is odd using the isOdd property.
  3. We print the result to standard output.

Dart Program

void main() {
  int num1 = 5;
  bool result1 = num1.isOdd;
  print('Is $num1 odd? $result1');
}

Output

Is 5 odd? true

2 Check if a positive number is even

In this example,

  1. We assign the value 8 to the integer variable num2.
  2. We check if num2 is odd using the isOdd property.
  3. We print the result to standard output.

Dart Program

void main() {
  int num2 = 8;
  bool result2 = num2.isOdd;
  print('Is $num2 odd? $result2');
}

Output

Is 8 odd? false

3 Check if a negative number is odd

In this example,

  1. We assign the value -3 to the integer variable num3.
  2. We check if num3 is odd using the isOdd property.
  3. We print the result to standard output.

Dart Program

void main() {
  int num3 = -3;
  bool result3 = num3.isOdd;
  print('Is $num3 odd? $result3');
}

Output

Is -3 odd? true

Summary

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